title: SmtpClient.SendAsync not sending email versus SmtpClient.Send
body: <p>I am working on a project which (unfortunately) requires the maximum framework allowable to be .NET 4.</p>
  
  <p>In this project I am attempting to send an email asynchronously using <code>SendAsync()</code> but for some reason, it fails to send (or rather, it just doesn't send). Simply put, nothing happens. No error or anything, whats strange is that when I set a breakpoint at the event handler code, and step through the program, it doesn't go into the event handler at any point.</p>
  
  <p>If I use the synchronous method <code>Send();</code> it works flawlessly.</p>
  
  <p>The only difference in my code is the using an event handler for the <code>SendAsync();</code> method. (<code>SendCompleteEventHandler</code>)</p>
  
  <p>below is the code I have tried so far to send an email.</p>
  
  <pre><code>private static void SendMailAsync()
  {
  
      const string FROM = "testmail@testmail.com";
      const string TO = "recipient@testmail.com";
  
      string SUBJECT = "THIS IS A TEST";
      string BODY = "THIS IS A TEST";
  
  
      const string SMTP_USERNAME = "UserName";  //SMTP username. 
      const string SMTP_PASSWORD = "Password";  // SMTP password.
  
  
      const string HOST = "host.testsmtp.com";
      const int PORT = 2587;
  
      // Create an SMTP client
      SmtpClient client = new SmtpClient(HOST, PORT);
      client.SendCompleted += new SendCompletedEventHandler(Client_SendComplete);
  
      // Create a network credential
      client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);
      client.EnableSsl = true;
  
      string userToken = "testmsg1";
  
      // Send the email. 
  
          client.SendAsync(FROM, TO, SUBJECT, BODY, userToken);
  
      client.Dispose();
  
  }
  
  private static void Client_SendComplete(object sender, AsyncCompletedEventArgs e)
  {
      string token = (string) e.UserState;
  
      if (e.Error != null)
      {
          MessageBox.Show(e.Error.ToString());
      }
      else
      {
          MessageBox.Show("Message sent.");
      }
  }
  
  private void button2_Click(object sender, EventArgs e)
  {
      SendMailAsync();
  }
  </code></pre>
  
  <p>Is there something I am just flat out missing? Thanks.</p>