Email
Thu Dec 07 2023 07:40:54 GMT+0000 (Coordinated Universal Time)
Saved by
@Samarmhamed78
var _email = new MimeMessage();
_email.From.Add(MailboxAddress.Parse(_config.GetSection("EmailConfiguration:Username").Value));
_email.To.AddRange(to.Select(x => MailboxAddress.Parse(x)).ToList());
_email.Subject = request.Subject;
if (parameters != null)
{
foreach (var parameter in parameters)
{
request.Body = request.Body.Replace(parameter.Key, parameter.Value);
}
}
_email.Body = new TextPart(TextFormat.Html) { Text = request.Body };
using var smtp = new SmtpClient();
await smtp.ConnectAsync(_config.GetSection("EmailConfiguration:Host").Value, 587, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync(_config.GetSection("EmailConfiguration:Username").Value, _config.GetSection("EmailConfiguration:Password").Value);
await smtp.SendAsync(_email);
await smtp.DisconnectAsync(true);
content_copyCOPY
Comments