public async Task <bool> MailSendFromContactAsync(SendMailByIdRequest sendMailByIdRequest, Guid id) { var mail = await DbContext.emailAccountLists.SingleOrDefaultAsync(x => x.Id == id); var message = new MimeMessage(); message.To.Add(new MailboxAddress(mail.Name, mail.Address)); message.From.Add(new MailboxAddress(sendMailByIdRequest.NameFrom, mail.Address)); message.Subject = sendMailByIdRequest.Subject; message.Body = new TextPart(TextFormat.Html) { Text = sendMailByIdRequest.Content }; using (var emailClient = new SmtpClient()) { emailClient.Connect(_emailConfiguration.SmtpServer, _emailConfiguration.SmtpPort, true); emailClient.AuthenticationMechanisms.Remove("XOAUTH2"); emailClient.Authenticate(_emailConfiguration.SmtpUsername, _emailConfiguration.SmtpPassword); emailClient.Send(message); emailClient.Disconnect(true); } return(true); }
public IActionResult MailSendByAccAndCont([FromRoute] Guid id, [FromRoute] Guid loginId, [FromBody] SendMailByIdRequest sendMailByIdRequest) { var result = MailSenderService.MailSendByAccAndContAsync(sendMailByIdRequest, id, loginId); return(Ok(result)); }
public IActionResult MailSendFromContact([FromRoute] Guid id, [FromBody] SendMailByIdRequest sendMailByIdRequest) { var result = MailSenderService.MailSendFromContactAsync(sendMailByIdRequest, id); return(Ok(result)); }