public static void SendEmailAsync(IConfiguration configuration, string codeVerification, string email, string name, HtmlEmailType type, HtmlEmailPersonType personType) { var htmlEmail = LoadHtmlBase(configuration, name, codeVerification, type, personType); var emailSend = new EmailSend { EmailTo = email, Message = "", Subject = (type == HtmlEmailType.ForgetPassword? "Redefinição de senha": "Confirmação de conta"), Body = htmlEmail }; var emailSerialize = JsonConvert.SerializeObject(emailSend); var data = new StringContent(emailSerialize, Encoding.UTF8, "application/json"); HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); }; var endPoint = "https://ec2-18-229-164-33.sa-east-1.compute.amazonaws.com/api/v1/email"; // Pass the handler to httpclient(from you are calling api) HttpClient client = new HttpClient(clientHandler); client.PostAsync(endPoint, data); }
public static string LoadHtmlBase(IConfiguration configuration, string name, string codeVerification, HtmlEmailType type, HtmlEmailPersonType personType) { var httpClient = new HttpClient(); var html = httpClient .GetStringAsync("https://relibre.s3-sa-east-1.amazonaws.com/example.html").Result; var settings = new HtmlSettings(); var emailSettings = new EmailSettings(configuration); configuration .GetSection(Constants.HtmlSettings).Bind(settings); string htmlFile = Path.GetFullPath(settings.IdetifierHtmlFile); HtmlDocument doc = new HtmlDocument(); // abrir arquivo doc.LoadHtml(html); // capturara elemento nome var elemento = doc.GetElementbyId(settings.IdentifierName); // alterar nome a ser apresentado ReplaceTextHtml(elemento, string.Format(Constants.HtmlEmailName, name)); // capturar elemento descricao elemento = doc.GetElementbyId(settings.IdentifierDescription); // alterar descrição ReplaceTextHtml(elemento, (type == HtmlEmailType.ForgetPassword ? Constants.HtmlEmailDescriptionPassword : Constants.HtmlEmailDescriptionAccount)); // capturar elemento informação elemento = doc.GetElementbyId(settings.IdentifierInformation); // alterar informação ReplaceTextHtml(elemento, (type == HtmlEmailType.ForgetPassword ? Constants.HtmlEmailInformationPassword : Constants.HtmlEmailInformationAccount)); // capturar elemento do botão elemento = doc.GetElementbyId(settings.IdentifierButton); ReplaceTextHtml(elemento, (type == HtmlEmailType.ForgetPassword ? Constants.HtmlEmailButtonTextPassword : Constants.HtmlEmailButtonTextAccount)); // alterar valor de redirecionamento elemento.SetAttributeValue("href", string.Format((type == HtmlEmailType.ForgetPassword ? settings.RedirectLinkPassword: settings.RedirectLinkAccount), codeVerification)); elemento.SetAttributeValue("data-saferedirecturl", string.Format((type == HtmlEmailType.ForgetPassword ? settings.RedirectLinkPassword: settings.RedirectLinkAccount), codeVerification)); elemento = doc.GetElementbyId(settings.IdentifierLinkRedirect); elemento.SetAttributeValue("href", (personType == HtmlEmailPersonType.LegalPerson)? Constants.HtmlEmailRedirectLinkLegalPerson : Constants.HtmlEmailRedirectLinkIndividualPerson); var result = doc.DocumentNode.OuterHtml; return(result); }