Make the send email using SMTP as async
This commit is contained in:
parent
3a2c8ccc4f
commit
73ba204c06
|
|
@ -52,14 +52,7 @@ namespace BotSharp.Plugin.EmailHandler.Functions
|
|||
{
|
||||
Text = body
|
||||
};
|
||||
|
||||
using (var smtpClient = new SmtpClient())
|
||||
{
|
||||
smtpClient.Connect(_emailSettings.SMTPServer, _emailSettings.SMTPPort, SecureSocketOptions.StartTls);
|
||||
smtpClient.Authenticate(_emailSettings.EmailAddress, _emailSettings.Password);
|
||||
smtpClient.Send(mailMessage);
|
||||
smtpClient.Disconnect(true);
|
||||
}
|
||||
await HandleSendEmailBySMTP(mailMessage);
|
||||
message.Content = $"Email successfully send over to {recipient}. Email Subject: {subject}";
|
||||
return true;
|
||||
}
|
||||
|
|
@ -71,5 +64,15 @@ namespace BotSharp.Plugin.EmailHandler.Functions
|
|||
return false;
|
||||
}
|
||||
}
|
||||
public async Task HandleSendEmailBySMTP(MimeMessage mailMessage)
|
||||
{
|
||||
using (var smtpClient = new SmtpClient())
|
||||
{
|
||||
await smtpClient.ConnectAsync(_emailSettings.SMTPServer, _emailSettings.SMTPPort, SecureSocketOptions.StartTls);
|
||||
await smtpClient.AuthenticateAsync(_emailSettings.EmailAddress, _emailSettings.Password);
|
||||
await smtpClient.SendAsync(mailMessage);
|
||||
smtpClient.Disconnect(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue