C # operation EML mail file instance (with HTML formatted message body and attachments)

Source: Internet
Author: User
Tags lexer

Use QQ mailbox, 163 mailbox, such as exported EML mail, contains the message sender, subject, content, attachments and other information, the instance on how to parse this information, and save after editing to do a demo.

As shown, the EML file is an encoded text file that can be used to identify keywords such as received, Sender, Cc, BCC, from, and so on, using regular expressions.

However, after parsing the content is encoded, such as sender's content x-qq-feat ..., this time needs to decode the content, generally using BASE64 encoding.

EML source files contain a lot of information, in addition to the recipient, sender, subject, body, attachments, etc. that the mailbox client sees, you can also view information such as the PC host name used by the sender, the mailbox client, the IP address sent, and the SMTP protocol configuration sent.

EML message content can be formatted, formatted EML message content is essentially an HTML tag string, so you can use the HTML processing library to process the formatted message content.

As shown in the TXT text string:

The HTML formatted text string is shown:

If we want to modify the contents of the message and retain the original format, we need to modify the HTML formatted message content, we need to parse the HTML, as shown in:

To make it easier to edit the contents of the message, you can extract the text content from the HTML and, when modified, apply the formatted label of the source text to the new text. As shown in modify the content interface:

Attachment content is directly embedded in the EML file, which can be parsed out, including the file name, transmission encoding format, file type, and can extract the contents of the file and then save to the local disk.

After the information is presented, you can edit it, including the sender, recipient of the basic information, you can also apply the source format to edit the message body content, add, delete message attachments.

Parse the HTML formatted message body, use the Htmlagilitypack library to process it, and you can also use Winista.htmlparser.

 Lexer Lexer = new Lexer (HTML); Parser Parser = new Parser (lexer); NodeList htmlnodes = parser.                Parse (null); if (Htmlnode is ITag)//html Node {ITag tag = (htmlnode as ITAG); if (!tag. Isendtag ()) {string nodestring = tag.                    TagName; if (tag. Attributes! = NULL && tag. Attributes.count > 0) {if (tag. attributes["ID"] = null) {nodestring = nodestring + "{id=\" "+ tag.a ttributes["ID"].                        ToString () + "\"} "; } if (tag. attributes["HREF"] = null) {nodestring = nodestring + "{href=\" "+ t Ag. attributes["HREF"].                        ToString () + "\"} ";                    }} current = new TreeNode (nodestring);                TREENODE.NODES.ADD (current); }            }

Other

There is a need for office assistance and other tools to develop friends, you can contact me to explore the work of the problem-solving solutions.

C # operation EML mail file instance (with HTML formatted message body and attachments)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.