tags:

views:

29

answers:

3

In the following code

public static void Send(SmtpClient smtpClient, MailMessage email)
{
    try
    {
        smtpClient.SendCompleted += (sender, e) =>
        {
            var x = e.Error; // can't access discarded object
        };
        smtpClient.SendAsync(email, null);
    }
    catch // never reach
    {
        // this works
        smtpClient.Send(email);
    }
}
A: 

Your mail can be recognized as spam. Check in your spam folder

Sergej Andrejev
Already did thousand times
BrunoLM
A: 

Not sure about this - but try passing in something other than null in the userToken

smtpClient.SendAsync(email, "test");
VoodooChild
+2  A: 

Your smtpClient object has been disposed or finalized after the call to Send has been completed but before the asynchronous send method can be run. Try moving the scope of the variable that is passed to the Send method so that it lasts through the asynchronous execution.

Another gotcha is that only one SendAsync call can be executed at a time. You have to implement your own wait queue in order to reliably use SendAsync or else an InvalidOperationException is thrown.

BC