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 async Task SendEmail_XMLTM() { ISendMailProvider sendMailProvider = FactoryMailProvider.CreateInstance(FactoryMailProvider.GetProviderFromConfig()); var sendMailParams = new Schema.SendMailParams() { HTMLContent = "<strong>Este es un correo de prueba</strong>", PlainContentText = "Este es un correo de prueba", Subject = "Cotorria entrega CFDI" }; var bytesContent = File.ReadAllBytes(Path.Combine(EmployerRegistrationUT.AssemblyDirectory, "testingFiles\\example.xml")); sendMailParams.SendMailAddresses.Add(new Schema.SendMailAddress() { Email = "*****@*****.**", Name = "Omar" }); sendMailParams.SendMailAttachments.Add(new Schema.SendMailAttachment() { Attachment = bytesContent, Filename = "cfdi.xml", TypeAttachment = TypeAttachment.XML }); await sendMailProvider.SendMailAsync(sendMailParams); }