Will mail.Dispose()
always be called after the SendMailAsync()
completes its call if I put mail.Dispose()
at the end? For example, if I am calling the Post()
a thousand times, the dispose should be called after each email is sent.
Here is my code:
public async Task Post(NotificationData notification)
{
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress(notification.Email));
mail.Subject = notification.Subject;
mail.Body = notification.Body;
using (SmtpClient smtp = new SmtpClient())
{
smtp.SendCompleted += new SendCompletedEventHandler(SmtpClient_SendCompleted);
await smtp.SendMailAsync(mail);
}
mail.Dispose();
}