title: HTML email not displaying correctly
body: <p>i have a strange problem with sending HTML mail in c#.</p>
  
  <p>Basically i am trying to email myself the weather every morning and I begin by downloading the weather in HTML markup from an ftp site.</p>
  
  <p>After obtaining the source file i then read it into a string and create a mailMessage using the following code.</p>
  
  <pre><code>string body = File.ReadAllText(@"C:\Weather.htm");
  
  MailMessage mailMessage = new MailMessage();
  SmtpClient mailClient = new SmtpClient("smtp.gmail.com");
  
  mailClient.Credentials = new NetworkCredential(username, password);
  mailClient.Port = 587;
  mailClient.EnableSsl = true;
  mailMessage.From = new MailAddress(emailFrom);
  mailMessage.IsBodyHtml = true;    
  mailMessage.To.Add(emailTo);
  mailMessage.Subject = "Test Email";
  mailMessage.SubjectEncoding = System.Text.Encoding.Unicode;
  mailMessage.Body = body;
  mailMessage.BodyEncoding = System.Text.Encoding.Unicode;
  mailClient.Send(mailMessage);
  </code></pre>
  
  <p>The problem is that whilst the email arrives in HTML format, all of the DIV / CSS are not respected and it looks weird. I have tried to email to a different email address &amp; client and it looks the same as well as trying different encodings.</p>
  
  <p>So somewhere along the line something is going wrong.</p>
  
  <p>Does anyone know how to fix this and get a properly formatted email?</p>
  
  <h1><strong>Good Image</strong></h1>
  
  <p><img src="https://i.stack.imgur.com/oNk4V.png" alt="alt text"></p>
  
  <h1><strong>BadImage</strong></h1>
  
  <p><img src="https://i.stack.imgur.com/MpVOm.png" alt="alt text"></p>
  
  <p>source markup</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;head xmlns=""&gt;
          &lt;META http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Sydney Forecast&lt;/title&gt;
          &lt;link rel="stylesheet" type="text/css" href="http://www.bom.gov.au/watl/standard/common.css"&gt;
          &lt;link rel="stylesheet" type="text/css" href="http://www.bom.gov.au/weather-services/styles/text-gfe.css"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="product"&gt;
              &lt;p xmlns="" class="p-id"&gt;IDN10064&lt;/p&gt;
              &lt;p xmlns="" class="source"&gt;Australian Government Bureau of Meteorology&lt;br/&gt;New South Wales
              &lt;h2 xmlns=""&gt;Updated Sydney Forecast&lt;/h2&gt;
              &lt;p xmlns="" class="date"&gt;Issued at 8:11 am&amp;nbsp;EST on Thursday 9 September 2010&lt;br&gt;for the period until midnight EST&amp;nbsp;Wednesday 15 September 2010.&lt;/p&gt;
              &lt;h3 xmlns="" class="warning"&gt;Warning Summary at issue time&lt;/h3&gt;
              &lt;p xmlns=""&gt;Nil.&lt;/p&gt;
              &lt;p xmlns="" class="p-id"&gt;Details of warnings are available on the Bureau's website www.bom.gov.au, by telephone 1300-659-218* or through some TV and radio broadcasts.&lt;/p&gt;
              &lt;h3 xmlns="" class="day"&gt;Forecast for the rest of Thursday&lt;/h3&gt;
              &lt;p xmlns="" class="sl"&gt;Cloud increasing. Areas of rain this afternoon and evening. Winds northerly averaging up to 20 km/h.&lt;/p&gt;
              &lt;div xmlns="" class="grid"&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;City Centre&lt;/div&gt;
                      &lt;div class="wx"&gt;A little rain later.&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;20&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line"&gt;
                      &lt;div class="rain_l"&gt;Chance of any rainfall:&lt;/div&gt;
                      &lt;div class="rain_prob_v"&gt;30%&lt;/div&gt;
                      &lt;div class="rain_l"&gt;Chance of no rainfall:&lt;/div&gt;
                      &lt;div class="rain_prob_v"&gt;70%&lt;/div&gt;
                      &lt;div class="rain_l"&gt;Rainfall:&lt;/div&gt;
                      &lt;div class="rain_v"&gt;0 to 1 mm&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;Penrith&lt;/div&gt;
                      &lt;div class="wx"&gt;Late rain.&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;20&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line"&gt;
                      &lt;div class="rain_l"&gt;Chance of any rainfall:&lt;/div&gt;
                      &lt;div class="rain_prob_v"&gt;30%&lt;/div&gt;
                      &lt;div class="rain_l"&gt;Chance of no rainfall:&lt;/div&gt;
                      &lt;div class="rain_prob_v"&gt;70%&lt;/div&gt;
                      &lt;div class="rain_l"&gt;Rainfall:&lt;/div&gt;
                      &lt;div class="rain_v"&gt;0 to 1 mm&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line"&gt;
                      &lt;div&gt;
                          &lt;h4&gt;Around Sydney&lt;/h4&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line"&gt;
                      &lt;div class="name"&gt;Liverpool&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;20&lt;/div&gt;
                      &lt;div class="name"&gt;Parramatta&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;20&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line"&gt;
                      &lt;div class="name"&gt;Terrey Hills&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;19&lt;/div&gt;
                      &lt;div class="name"&gt;Campbelltown&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;19&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line"&gt;
                      &lt;div class="name"&gt;Richmond&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;20&lt;/div&gt;
                      &lt;div class="name"&gt;Bondi&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;19&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;p xmlns="" class="sl"&gt;Fire Danger: Low to Moderate [0-11]&lt;/p&gt;
              &lt;p xmlns="" class="sl"&gt;UV Alert from 9:10 am to 2:40 pm, UV Index predicted to reach 6 [High]&lt;/p&gt;
              &lt;h3 xmlns="" class="day"&gt;Forecast for Friday&lt;/h3&gt;
              &lt;p xmlns="" class="sl"&gt;Partly cloudy. Winds west to northwesterly averaging up to 25 km/h tending westerly up to 40 km/h around midday.&lt;/p&gt;
              &lt;div xmlns="" class="grid"&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;City Centre&lt;/div&gt;
                      &lt;div class="wx"&gt;Becoming windy.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;13&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;22&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;Penrith&lt;/div&gt;
                      &lt;div class="wx"&gt;Partly cloudy. Becoming windy.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;11&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;23&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;h3 xmlns="" class="day"&gt;Forecast for Saturday&lt;/h3&gt;
              &lt;p xmlns="" class="sl"&gt;Sunny. Winds west to southwesterly averaging up to 25 km/h tending mainly southeast to southwesterly up to 20 km/h around midday.&lt;/p&gt;
              &lt;div xmlns="" class="grid"&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;City Centre&lt;/div&gt;
                      &lt;div class="wx"&gt;Sunny.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;12&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;21&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;Penrith&lt;/div&gt;
                      &lt;div class="wx"&gt;Sunny.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;9&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;22&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;h3 xmlns="" class="day"&gt;Forecast for Sunday&lt;/h3&gt;
              &lt;p xmlns="" class="sl"&gt;Mostly sunny. Light winds.&lt;/p&gt;
              &lt;div xmlns="" class="grid"&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;City Centre&lt;/div&gt;
                      &lt;div class="wx"&gt;Mostly sunny.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;10&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;21&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;Penrith&lt;/div&gt;
                      &lt;div class="wx"&gt;Sunny.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;6&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;23&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;h3 xmlns="" class="day"&gt;Forecast for Monday&lt;/h3&gt;
              &lt;p xmlns="" class="sl"&gt;Becoming cloudy. Isolated showers later in the day. Winds west to southwesterly averaging up to 25 km/h.&lt;/p&gt;
              &lt;div xmlns="" class="grid"&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;City Centre&lt;/div&gt;
                      &lt;div class="wx"&gt;Shower or two developing.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;13&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;22&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;Penrith&lt;/div&gt;
                      &lt;div class="wx"&gt;Shower or two developing.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;10&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;22&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;h3 xmlns="" class="day"&gt;Forecast for Tuesday&lt;/h3&gt;
              &lt;p xmlns="" class="sl"&gt;Sunny. Light winds tending north to northeasterly up to 20 km/h during the evening.&lt;/p&gt;
              &lt;div xmlns="" class="grid"&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;City Centre&lt;/div&gt;
                      &lt;div class="wx"&gt;Sunny.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;12&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;19&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;Penrith&lt;/div&gt;
                      &lt;div class="wx"&gt;Sunny.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;10&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;19&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;h3 xmlns="" class="day"&gt;Forecast for Wednesday&lt;/h3&gt;
              &lt;p xmlns="" class="sl"&gt;Isolated showers during the morning. Sunny afternoon. Winds northwesterly averaging up to 25 km/h tending westerly up to 35 km/h during the morning.&lt;/p&gt;
              &lt;div xmlns="" class="grid"&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;City Centre&lt;/div&gt;
                      &lt;div class="wx"&gt;Shower or two clearing.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;12&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;20&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="line space-b"&gt;
                      &lt;div class="name"&gt;Penrith&lt;/div&gt;
                      &lt;div class="wx"&gt;Shower or two clearing.&lt;/div&gt;
                      &lt;div class="min_l"&gt;Min&lt;/div&gt;
                      &lt;div class="min_v"&gt;8&lt;/div&gt;
                      &lt;div class="max_l"&gt;Max&lt;/div&gt;
                      &lt;div class="max_v"&gt;21&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;p xmlns="" class="dt"&gt;The next routine forecast will be issued at 4:20 pm&amp;nbsp;EST&amp;nbsp;Thursday.&lt;/p&gt;
              &lt;p xmlns="" class="p-id"&gt;* Calls to 1300 numbers cost around 27.5c incl. GST, higher from mobiles or public phones.&lt;/p&gt;
          &lt;/div&gt;
  &lt;/html&gt;
  </code></pre>