Your problem is that SmtpClient
is disposed before the email is sent.
Two ways:
Await the
SendMailAsync
resultusing (var client = new SmtpClient()) { await client.SendMailAsync(email); }
Register the
SendCompleted
event and dispose theSmtpClient
only after the message is sentvar client = new SmtpClient(); client.SendCompleted += (s, e) => { client.Dispose(); }; return client.SendMailAsync(message);