public async Task <IActionResult> SendEmailReport([FromBody] SendEmailParameterModel destinationEmail) { if (await _sendEmailServices.SendEmail(destinationEmail)) { return(Ok(true)); } else { return(Ok(false)); } }
public async Task <bool> SendEmail(SendEmailParameterModel emailDestino) { try { string EmailOrigen = _sendEmailConfig.Email; //string EmailDestino = "*****@*****.**"; //string EmailDestino = "*****@*****.**"; string EmailDestino = emailDestino.destinationEmail; string Contraseña = _sendEmailConfig.Pass; //string path = @"C:\Users\CNFCASTRO-NB\source\repos\ConsoleApp1\ConsoleApp1\adjuntos\Bliss.jpg"; //string path2 = @"C:\Users\CNFCASTRO-NB\source\repos\ConsoleApp1\ConsoleApp1\adjuntos\CertificadoAfiliacion.pdf"; //string path3 = @"C:\Users\CNFCASTRO-NB\source\repos\ConsoleApp1\ConsoleApp1\adjuntos\Nuevo Hoja de cálculo de Microsoft Excel.xlsx"; MailMessage oMailMessage = new MailMessage(EmailOrigen, EmailDestino, _sendEmailConfig.AsuntoReporteVenta, _sendEmailConfig.CuerpoReporteVenta); //oMailMessage.Attachments.Add(new Attachment(path)); //oMailMessage.Attachments.Add(new Attachment(path2)); //oMailMessage.Attachments.Add(new Attachment(path3)); oMailMessage.IsBodyHtml = true; SmtpClient oSmtpCliente = new SmtpClient(_sendEmailConfig.SmtpClientEmail); oSmtpCliente.EnableSsl = true; oSmtpCliente.UseDefaultCredentials = false; oSmtpCliente.Port = _sendEmailConfig.EmailPort; oSmtpCliente.Credentials = new System.Net.NetworkCredential(EmailOrigen, Contraseña); oSmtpCliente.Send(oMailMessage); oSmtpCliente.Dispose(); return(true); } catch (Exception) { return(false); throw; } }