Question

Is anybody aware of any libraries for working with MHT files (Multi-Part MIME files) in .NET? I need to programmatically extract the contents from an existing MHT file containing a Flash website. I haven't been able to locate any such libraries.

Also, if there's a native way in .NET that I'm not aware of, please feel free to let me know.

EDIT: I know that the MailMessage class supports multi-part MIME messages through the AlternateViews property. The AlternateView class represents the alternative views in a multi-part MIME message. I'd like to believe that it's possible to use this knowledge to build something using code native to the .NET framework. I just haven't been able to find out the right combination to make it work, so I'm starting to loose faith. Does anybody out there know if it's possible to extract the contents of a MHT file through the AlternateView and other related classes? For example, it would be nice if it were possible to create an instance of the MailMessage class from a Stream.

Was it helpful?

Solution

You might be interessed in my MIME parsing project at github (written in C#)

https://github.com/smithimage/MIMER/

Also has a Nuget package:

https://nuget.org/packages/MIMER/

OTHER TIPS

http://www.lumisoft.ee/lswww/ENG/Products/Mail_Server/mail_index_eng.aspx?type=info

This is open source email server which has good Mime Parser.

David benko did a great job here his github project. I recently faced a this issue where I had an mhtml that needed to be converted to HTML file. for that I used HTMLAgility pack dll to extract content from the mhtml file and feed in this content to David's provided library:

string filePath = @"D:\Temp\myfile.mhtml";
var doc = new HtmlDocument();
doc.Load(filePath);
string mhtml = doc.DocumentNode.OuterHtml;
MHTMLParser parser = new MHTMLParser(mhtml);
string htmlContent = parser.getHTMLText();
System.IO.File.WriteAllText(@"D:\Temp\file.html", htmlContent);

I would really appreciate if someone could verify this approach. Cheers Vaqar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top