i am trying to send email async method , but no email sent
https://dotnetfiddle.net/oFVtN2
Because of your 'fire and forget', you are disposing of the mail message immediately; that may be affecting you. Also, you're not disposing of the mail client. You should put the entire operation into the "fire and forget", including the creation and disposal of SmtpClient. Something more like this:
FireAndForgetTask(async cancellationToken =>
{
using(var smtp = new SmtpClient
{
Host = "myhost",
Port = 587,
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("myemail", "mypass"),
Timeout = 50000
})
{
using (var message = new MailMessage("myemail", destMail)
{
Subject = subject,
Body = mailBody,
IsBodyHtml = html
})
{
await smtp.SendMailAsync(message);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With