I had the following for emailing, which worked:
private SmtpClient _client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("address@gmail.com", "password"),
EnableSsl = true
};
public void DoThis(){
_client.Send("from@gmail.com", to.Email, "Subject", "Body");}
public void DoThat(){
_client.Send("from@gmail.com", to.Email, "Subject", "Body");}
But it was blocking the web application until the email was sent, so I decided to try sending Asynchronously:
public void DoThis(){
var message = new MailMessage("from@gmail.com", to.Email, "Subject", "Body");
_client.SendAsync(message, null);
}
Which I can see getting treated asynchronously if I debug, but I always get the following:
An asynchronous module or handler completed while an asynchronous operation was still pending.
What am I doing wrong?