title: ASP.net / C# Email with AlternateViews to Show HTML not the PlainText
body: <p>Currently I can properly send an HTML email with ASP.net. I noticed that using a spam tester such <a href="https://www.mail-tester.com/" rel="nofollow">https://www.mail-tester.com/</a> would give a better score if you supplied both a plain text view as well as the HTML view. So i decided to try to add the alternate views. My issues is that if I try and add a plain text view it seems to override the HTML View. Here is the code that works perfectly fine for setting up my HTML only view:</p>
  
  <pre><code>    message.IsBodyHtml = true;
      message.BodyEncoding = Encoding.UTF8;
      message.BodyTransferEncoding = TransferEncoding.Base64;
      message.Body = "&lt;html lang=\"en\"&gt;&lt;head&gt;&lt;meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"&gt;&lt;/head&gt;&lt;body&gt;" + message.Body + "&lt;/body&gt;&lt;/html&gt;";
  </code></pre>
  
  <p>Now if I try to add the plain view Gmail seems to only want to display the plain text view and not the HTML view. Is there anyway to set which view is default? Here is my plain text view code:</p>
  
  <pre><code>    message.IsBodyHtml = true;
      message.BodyEncoding = Encoding.UTF8;
      message.BodyTransferEncoding = TransferEncoding.Base64;
      message.Body = "&lt;html lang=\"en\"&gt;&lt;head&gt;&lt;meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"&gt;&lt;/head&gt;&lt;body&gt;" + message.Body + "&lt;/body&gt;&lt;/html&gt;";
  
      //first we create the Plain Text part
      var plainView = AlternateView.CreateAlternateViewFromString(HtmlToPlainText(message.Body), Encoding.UTF8, MediaTypeNames.Text.Plain);
      ////then we create the Html part
      var htmlView = AlternateView.CreateAlternateViewFromString(message.Body, Encoding.UTF8, MediaTypeNames.Text.Html);
      message.AlternateViews.Add(htmlView);
      message.AlternateViews.Add(plainView);
  </code></pre>
  
  <p>I have tried removing first displayed code for the body and setting the body to empty string so that it only adds both of the alternate views and that did not work. I believe I covered all permutations of the code and still nothing. Like I said it works perfectly for HTML only and it works with html alternate view but not when adding the plain text view.</p>