troubleshooting Question

smtp SendAsync always throws error "Failure sending email"

Avatar of SweatCoder
SweatCoderFlag for United States of America asked on
ASP.NET
5 Comments1 Solution2963 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros