I’m trying to send an email async so it doesn’t slow down my front end (Asp.Net MVC).
SmtpClient smtp = new SmtpClient(_mailServer, 25);
smtp.UseDefaultCredentials = true;
MailMessage message = new MailMessage();
// ...etc
smtp.SendA(message); // this works fine
smtp.SendAsync(message, null); // if i change it to this, it doesn't work (mail never appears)
I don’t really undestand what the 2nd param to SendAsync is for.
MSDN says its an object to pass to the method that is invoked when the operation completes
well, wtf? what method? So I’ve just tried passing null as I don’t really understand what this is for, but obviously something is wrong.
Essentially it’s an object that you want passed in the send completed event.
When you use SendAsync, the event SendCompleted occurs. You then handle that event so that you know that you can send another email. The main reason for this is because you can only send one email at a time.