public async Task SendMailAsync(SendMailParams sendMailParams) { var client = new SendGridClient(_sendGridAPIKey); var from = new EmailAddress(_deliveryAccountEmail, _deliveryAccountDescription); var subject = sendMailParams.Subject; var tos = new List <EmailAddress>(); sendMailParams.SendMailAddresses.ForEach(p => { tos.Add(new EmailAddress(p.Email, p.Name)); }); var plainTextContent = sendMailParams.PlainContentText; var htmlContent = sendMailParams.HTMLContent; var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, tos, subject, plainTextContent, htmlContent); if (sendMailParams.SendMailAttachments.Any()) { msg.Attachments = new List <Attachment>(); //Example attachment sendMailParams.SendMailAttachments.ForEach(sendMailAttachment => { var typeOfAttachment = String.Empty; if (sendMailAttachment.TypeAttachment == TypeAttachment.PDF) { typeOfAttachment = System.Net.Mime.MediaTypeNames.Application.Pdf; } else if (sendMailAttachment.TypeAttachment == TypeAttachment.XML) { typeOfAttachment = System.Net.Mime.MediaTypeNames.Application.Xml; } else if (sendMailAttachment.TypeAttachment == TypeAttachment.TXT) { typeOfAttachment = TXT_TYPE_ATTACHMENT; } var attachment = new SendGrid.Helpers.Mail.Attachment { Content = Convert.ToBase64String(sendMailAttachment.Attachment), Filename = sendMailAttachment.Filename, Type = typeOfAttachment, Disposition = DISPOSITION }; msg.Attachments.Add(attachment); }); } var response = await client.SendEmailAsync(msg); if (response.StatusCode != System.Net.HttpStatusCode.Accepted) { throw new CotorraException(9101, "9101", SENDMAIL_GENERIC_EXCEPTION, null); } }
private async Task sendMailAsync(Overdraft overdraftToStamp, Guid UUID, string XML, byte[] PDF, ISendMailProvider sendMailProvider, List <PayrollCompanyConfiguration> payrollCompanyConfigurations) { if (!String.IsNullOrEmpty(overdraftToStamp.HistoricEmployee.Email)) { var message = new StringBuilder(); message.Append($"Estimado(a) {overdraftToStamp.HistoricEmployee.FullName},"); message.AppendLine(); message.AppendLine("Por parte de tu empresa en la que estas colaborando te mandamos los datos de tu recibo de nómina."); message.AppendLine($"Periodo: <strong>{overdraftToStamp.HistoricEmployee.PeriodTypeDescription} {overdraftToStamp.PeriodDetail.InitialDate.ToShortDateString()} al {overdraftToStamp.PeriodDetail.FinalDate.ToShortDateString()}.</strong>"); message.AppendLine($"RFC Emisor: <strong>{payrollCompanyConfigurations.FirstOrDefault().RFC}</strong>"); message.AppendLine($"Razón Social: <strong>{payrollCompanyConfigurations.FirstOrDefault().SocialReason}</strong>"); message.AppendLine($"UUID: <strong>{UUID}</strong>"); var sendindParams = new SendMailParams() { HTMLContent = message.ToString(), SendMailAddresses = new List <SendMailAddress>() { new SendMailAddress() { Email = overdraftToStamp.HistoricEmployee.Email, Name = overdraftToStamp.HistoricEmployee.FullName } }, PlainContentText = message.ToString(), SendMailAttachments = new List <SendMailAttachment>() { new SendMailAttachment() { Attachment = Encoding.UTF8.GetBytes(XML), Filename = $"{UUID}.xml", TypeAttachment = TypeAttachment.XML }, }, Subject = "Cotorria - Envío de recibo de nómina", }; if (PDF != null) { sendindParams.SendMailAttachments.Add(new SendMailAttachment() { Attachment = PDF, Filename = $"{UUID}.pdf", TypeAttachment = TypeAttachment.PDF }); } await sendMailProvider.SendMailAsync(sendindParams); } }
public void SendRecoverPasswordMail(string emailFrom, string emailTo, string url) { var template = new RecoverPasswordMailTemplate(nome: emailTo, link: url, logoUrl: _boAccountContentProvider.GetLogoUrl()); var client = new MailClient(); var mailParams = new SendMailParams { Subject = "Recuperação de Senha", Body = template.GetHtml(), IsBodyHtml = true, EmailFrom = "FwLog Sistema <" + emailFrom + ">", EmailsTo = emailTo, Attachments = null, BodyEncoding = Encoding.Default }; client.SendMail(mailParams); }
/// <summary> /// Send mail /// </summary> /// <param name="employeeIdentityRegistration"></param> /// <returns></returns> private async Task sendMailToEmployee(EmployeeIdentityRegistration employeeIdentityRegistration) { var bodyContent = "Bienvenido a Cotorria, tu empresa te invita a usar la App Móvil de Cotorria, te mandamos tu código de activación "; var mailProvider = FactoryMailProvider.CreateInstance(FactoryMailProvider.GetProviderFromConfig()); var sendParams = new SendMailParams() { HTMLContent = $"{bodyContent}: {employeeIdentityRegistration.ActivationCode}", PlainContentText = $"{bodyContent}: {employeeIdentityRegistration.ActivationCode}", SendMailAddresses = new List <SendMailAddress>() { new SendMailAddress() { Email = employeeIdentityRegistration.Email } }, Subject = "Invitación a Cotorria" }; await mailProvider.SendMailAsync(sendParams); }
public async Task SendRedefinePasswordEmail(SendRedefinePasswordEmailRequest request) { string redefinePasswordUrl = ConfigurationManager.AppSettings["RedefinePasswordUrl"]; string backofficeUrl = ConfigurationManager.AppSettings["BackofficeUrl"]; string mailFrom = ConfigurationManager.AppSettings["EmailFromRecoverPassword"]; var logoUrl = string.Concat(backofficeUrl, "/Content/images/logo.png"); var url = string.Format(redefinePasswordUrl, request.UserId, request.Token); var template = new RecoverPasswordMailTemplate(nome: request.UserEmail, link: url, logoUrl: logoUrl); var mailParams = new SendMailParams { Subject = GeneralStrings.RecoverPasswordEmailSubject, Body = template.GetHtml(), IsBodyHtml = true, EmailFrom = mailFrom, EmailsTo = request.UserEmail, Attachments = null, BodyEncoding = Encoding.Default }; var client = new MailClient(); await client.SendMailAsync(mailParams); }