Extracting Content from MHT Document

2020-07-20 04:13发布

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.

标签: c# .net mhtml
3条回答
Explosion°爆炸
2楼-- · 2020-07-20 04:53

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

查看更多
虎瘦雄心在
3楼-- · 2020-07-20 04:55

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.

查看更多
爷的心禁止访问
4楼-- · 2020-07-20 05:02

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/

查看更多
登录 后发表回答