title: Using System.Net.Mail to send emails - using the synchronous method 'Send' works, but 'SendAsync' does not
body: <p>I'm trying to send emails using F#, and found a code snippet that seems to work when using <code>Send</code>. I'm using gmail accounts and made sure that the sender account enables less secure apps to use it and that the email &amp; password combo is correct. I'm also using port <code>587</code>. <code>SendAsync</code> does not seem to work, but it's also not throwing any exceptions which seems strange.</p>
  <pre><code>let sendMailMessage email topic msg =
      let msg = new MailMessage(sender, email, topic, msg)
      msg.IsBodyHtml &lt;- false
  
      let client = new SmtpClient(server, port)
      client.EnableSsl &lt;- true
      client.UseDefaultCredentials &lt;- false
      client.Credentials &lt;- System.Net.NetworkCredential(sender, password)
  
      client.SendCompleted |&gt; Observable.add(fun e -&gt;
          let msg = e.UserState :?&gt; MailMessage
          if e.Cancelled then
              (&quot;Mail message cancelled:\r\n&quot; + msg.Subject) |&gt; Console.WriteLine
          if e.Error &lt;&gt; null then
              (&quot;Sending mail failed for message:\r\n&quot; + msg.Subject + &quot;, reason:\r\n&quot; + e.Error.ToString()) |&gt; Console.WriteLine
          if msg &lt;&gt; Unchecked.defaultof&lt;MailMessage&gt; then
              msg.Dispose()
          if client&lt;&gt;Unchecked.defaultof&lt;SmtpClient&gt; then
              client.Dispose()
      )
  
      try
          client.SendAsync(msg, msg) // runs fine but doesn't actually send an email
          client.Send(msg) // this works, but it's also blocking
      with
      | e -&gt; printfn &quot;%A&quot; e
  </code></pre>
  <p>I'm wondering if I'm doing anything wrong. I'm currently straight up calling the function from main in a test project.</p>