title: SMTP send mail cancelled
body: <p>Try to send a mail, but the task is cancelled. Any idea why?</p>
  
  <pre><code>public static Task SendAsync(this SmtpClient client, MailMessage message)
  {
      TaskCompletionSource&lt;object&gt; tcs = new TaskCompletionSource&lt;object&gt;();
      Guid sendGuid = Guid.NewGuid();
  
      SendCompletedEventHandler handler = null;
      handler = (o, ea) =&gt;
      {
          if (ea.UserState is Guid &amp;&amp; ((Guid)ea.UserState) == sendGuid)
          {
              client.SendCompleted -= handler;
              if (ea.Cancelled)
              {
                  tcs.SetCanceled(); // TASK CANCELLED: Why?
              }
              else if (ea.Error != null)
              {
                  tcs.SetException(ea.Error);
              }
              else
              {
                  tcs.SetResult(null);
              }
          }
      };
  
      client.SendCompleted += handler;
      client.SendAsync(message, sendGuid);
      return tcs.Task;
  }
  </code></pre>
  
  <p>Called by:</p>
  
  <pre><code>using( SmtpClient smtpClient = new SmtpClient() )
  {
      return smtpClient.SendAsync(msg);
  }
  </code></pre>
  
  <p>Thanks in advance for any help!
  Gerard</p>