title: Parsing email body with c#
body: <p>I have a database table of email called email_archive.  The table includes a field called body and another called raw_headers.  I want to display the contents of this table on screen using C# (in a SharePoint webpart).  I've been trying to find a library that can parse the body so that I can return the parts of the message to the window.  I've tried a library from Limilabs as well as downloaded a couple of other libraries. However, all appear to require an email in EML format at the very minimal.  </p>
  
  <p>The latest attempt was trying to use <a href="http://mailutilities.codeplex.com/" rel="nofollow">MailUtilies</a>.</p>
  
  <pre><code>MimeMessage mm = new MimeMessage(header + message);
  </code></pre>
  
  <p>But this is failing because it appears the format is not passing the MimeMessage integrity check.  </p>
  
  <p>Does anyone know of a way to parse an email into it's component parts using the raw headers and body content.</p>
  
  <p>The headers look like this</p>
  
  <pre><code>MIME-Version: 1.0
  Received: from server.domain.com (10.20.205.104) by
   mail.domain.com (xx.xx.xx.xx) with Microsoft SMTP Server id
   8.1.436.0; Mon, 16 Sep 2013 14:33:54 -0700
  Received: from server (localhost.localdomain [127.0.0.1])   by
   server.domain.com (8.13.8/8.13.8) with ESMTP id r8GLX4vm007046 for
   &lt;myaddress@domain.com&gt;; Mon, 16 Sep 2013 14:33:04 -0700
  From: "service@domain.com" &lt;service@domain.com&gt;
  To: My Name &lt;myaddress@domain.com&gt;
  Date: Mon, 16 Sep 2013 14:33:04 -0700
  Subject: Some Topic
  Thread-Topic: Some Topic
  Thread-Index: Ac6zJHFgOvb7ZAdeTJC8DzqnAvdnOw==
  Message-ID: &lt;153372.442207427-sendEmail@gserver&gt;
  Reply-To: "service@domain.com" &lt;service@domain.com&gt;
  Accept-Language: en-US
  Content-Language: en-US
  X-MS-Exchange-Organization-AuthAs: Internal
  X-MS-Exchange-Organization-AuthMechanism: 10
  X-MS-Exchange-Organization-AuthSource: mail.domain.com
  X-MS-Has-Attach:
  X-MS-TNEF-Correlator:
  Content-Type: multipart/alternative;
      boundary="_000_153372442207427sendEmailgroundwork_"
  </code></pre>
  
  <p>And the message looks something like this</p>
  
  <pre><code>--_000_153372442207427sendEmailgroundwork_
  Content-Type: text/plain; charset="iso-8859-1"
  Content-Transfer-Encoding: quoted-printable
  
  Some message to dispaly
  
  --_000_153372442207427sendEmailgroundwork_
  Content-Type: text/html; charset="iso-8859-1"
  Content-Transfer-Encoding: quoted-printable
  
  &lt;html&gt;&lt;head&gt;&lt;style type=3D'text/css'&gt; p,h1 { font-family: arial; } 
  &lt;/style&gt;&lt;/head&gt;&lt;body&gt;
   &lt;p&gt;Some message to display&lt;/p&gt;
   &lt;/body&gt;&lt;/html&gt;
  
  
  --_000_153372442207427sendEmailgroundwork_--
  </code></pre>