I have an ASP.NET web page that calls a separate class library that attempts to send email async. When I send the email synchronously, it works perfectly:
smtp.Send(mail)
but when I send async:
smtp.SendCompleted += new SendCompletedEventHandler(SendEmailCompletedCallback);
smtp.SendAsync(mail, GetUserIDFromCookie());
private static void SendEmailCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
// Get the unique identifier for this asynchronous operation.
//int token = int.Parse(e.UserState.ToString());
if (e.Cancelled)
{
WriteLog("SendEmailCompletedCallback", "Async email cancelled.");
}
if (e.Error != null)
{
WriteLog("SendEmailCompletedCallback", "Async email error: " + e.Error.ToString());
}
else
{
WriteLog("SendEmailCompletedCallback", "Async email sent!");
}
}
The callback method is never reached. Exception thrown during SendAsync(..).
Everything else is the same. Credentials the same for both methods. I have Async="true" in my @Page declaration on the calling aspx page.
I have googled on this for awhile and read several articles. I can't find anything I'm missing.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.