private async Task SendAsync(MimeMessage mailMessage)
{
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
try
{
await client.ConnectAsync(_emailConfig.SmtpServer, _emailConfig.PortResetPassword, true);
client.AuthenticationMechanisms.Remove("XOAUTH2");
await client.AuthenticateAsync(_emailConfig.UserName, _emailConfig.Password);
await client.SendAsync(mailMessage);
}
catch
{
//log an error message or throw an exception, or both.
throw;
}
finally
{
await client.DisconnectAsync(true);
client.Dispose();
}
}
}