title: "The type initializer for 'MailKit.Net.Smtp.SmtpClient' threw an exception"
body: <p>In VS-2022, .Net 6, Blazor WASM, C#, MailKit 3.1.1.</p>
  <p>I am getting this error <code>&quot;The type initializer for 'MailKit.Net.Smtp.SmtpClient' threw an exception&quot;</code> on this source-code <strong>when trying to instantiate SmtpClient</strong>:</p>
  <p>// NEW INFORMATION:
  InnerExeption is: 'System.PlatformNotSupportedException: System.Net.NetworkInformation is not supported on this platform. at System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties() at MailKit.Net.Smtp.SmtpClient..cctor()' –
  So now, MS recommends MailKit and then MailKit does not support .Net 6. What gives?</p>
  <blockquote>
  <p>from MSDN &quot;SmtpClient Class&quot;</p>
  <p>Remarks</p>
  <p>The SmtpClient class is used to send email to an SMTP server
  for delivery. The SMTP protocol is defined in RFC 2821, which is
  available at <a href="https://www.ietf.org" rel="nofollow noreferrer">https://www.ietf.org</a>.</p>
  <p>Important</p>
  <p>We don't recommend that you use the SmtpClient class for new
  development because SmtpClient doesn't support many modern protocols.
  <strong>Use MailKit or other libraries instead.</strong> For more information, see
  SmtpClient shouldn't be used on GitHub.</p>
  </blockquote>
  <p>Did .Net 6 interfere with MailKit working?  Your comments are welcome...Thanks</p>
  <pre><code>@page &quot;/mailkittestpage&quot;
  
  @using Microsoft.AspNetCore.Components.Forms
  @using myVSProject.Client.Services
  @using myVSProject.Shared
  @using System.ComponentModel.DataAnnotations
  @inject NavigationManager _navigationManager
  @using System.Net.Http
  @using System.Net.Http.Json
  @inject HttpClient Http
  @using MailKit.Net.Smtp
  @using MailKit.Security
  @using MimeKit
  @using MimeKit.Text
  
  &lt;h3&gt;Email Test Page&lt;/h3&gt;
  &lt;hr /&gt;
  &lt;div class=&quot;button-container&quot;&gt;
     &lt;button type=&quot;button&quot; class=&quot;e-btn e-normal e-primary&quot; @onclick=&quot;SendEmail&quot;&gt;Send Email&lt;/button&gt;
  &lt;/div&gt;
  
  @code {
      //&gt;&gt;&gt; other code omitted &lt;&lt;&lt;//
  
      public void SendEmail() {
          
      // Button-click event to Send Email.
      email.From.Add(MailboxAddress.Parse(&quot;aaaaaaaaa@hotmail.com&quot;));
      email.To.Add(MailboxAddress.Parse(&quot;bbbbbbbbbb@outlook.com&quot;));
      email.Subject = &quot;Email Subject goes here&quot;;
      email.Body = new TextPart(TextFormat.Plain) { Text = &quot;This is the body of the email&quot; };
  
      // send email
      try {
          using var smtp = new MailKit.Net.Smtp.SmtpClient();          &lt;== this line FAILS.
  
          smtp.ServerCertificateValidationCallback = (s, c, h, e) =&gt; true;
          smtp.Connect(&quot;smtp.office365.com&quot;, 587, SecureSocketOptions.StartTls);          
          smtp.Authenticate(&quot;aaaaaaaaa@outlook.com&quot;, &quot;ppppppwwwwww&quot;);
          smtp.Send(email);
          smtp.Disconnect(true);
      } catch (Exception ex) {
          Console.WriteLine($&quot;\r\n\n\nError sending email is '{ex.Message}'.&quot;);
      }
    }
  }
  </code></pre>