Use QQ mailbox 、163 E-mail, etc EML mail , Contains the sender of the message 、 The theme 、 Content 、 Attachments and all the information , This example is about how to parse this information , And save it after editing to make a Demo.

As shown in the figure below ,EML A file is a coded text file , You can use regular expressions to identify keywords , for example Received、Sender、Cc、Bcc、From etc. .

But the parsed content is encoded , for example Sender The content of X-QQ-FEAT……, It's time to decode the content , In general use Base64 Encoding .

EML The source file contains a lot of information , In addition to using the recipients seen by the mailbox client 、 Sender 、 The theme 、 Text 、 Accessories, etc , You can also view the PC Host name 、 Mailbox client , Sent IP Address , Sent SMTP Protocol configuration and other information .

EML Email content can be formatted , Formatted EML The essence of the email content is HTML Tag string , So you can use HTML The processing library processes the formatted mail content .

As shown in the figure below TXT Text string :

The picture below shows HTML Formatted text string :

If we want to change the content of the email , And keep the original format , It needs to be modified HTML Formatted message content , At this time, we need to HTML Analyze it , As shown in the figure below :

To make it easier to edit the content of the email , Can be HTML Extract the text content from , After modification , Apply the formatting label of the source text to the new text . The following figure shows the modify content interface :

The attachment content is embedded directly into EML In the document , You can tell from it , Include the file name 、 Transmission coding format 、 file type , And can extract the content of the file and save it to the local disk .

When the information comes out , It can be edited , Including the sender 、 The basic information of the recipient , You can also use the source format to edit the body of the message , add to 、 Delete email attachment .

analysis HTML Formatted message body , Use HtmlAgilityPack Library processing , In addition, you can 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.Attributes["ID"].ToString() + "\" }";
if (tag.Attributes["HREF"] != null)
nodeString = nodeString + " { href=\"" + tag.Attributes["HREF"].ToString() + "\" }";
current = new TreeNode(nodeString);

another ,

There are friends who need to develop office assistant tools , You can contact me , Explore solutions to problems at work .

C# operation EML Mail file instance ( contain HTML Format the message body and attachments ) More articles about

  1. C# operation VFP Of dbf Database file instance

    C# operation VFP Of dbf Database file instance A new one : js Get the website and path In the example, we use Oledb and Odbc operation vfp database dbf file , Operations include : Read , Additions and deletions . It has been tested and can be used directly , Usage method : The following code is divided into two parts ...

  2. python From introduction to the great God ---4、python3 The simplest example of file operation

    python From introduction to the great God ---4.python3 The simplest example of file operation One . summary One sentence summary : python File manipulation is really simple , The function of file operation is called directly in the code open().read(), There is no need to introduce the package ...

  3. javamail Simulate mailbox function -- Email reply - Intermediate combat 【 Email reply method 】(javamail API Email instance )

    introduction : JavaMai Download address l jar package : This article is closely related to the previous article , reader ...

  4. java Mail delivery ( Including accessories )

    1. [ Code ]java Mail delivery ( Including accessories ) Maniac IT The person stationmaster arranges : utilize Java Send E-mail ( Including accessories ) Example :1. Configuration of email sending propertity The contents of the document are as follows :( Files in sr ...

  5. JAVASE02-Unit06: File operations ——File 、 File operations —— RandomAccessFile

    Unit06: File operations --File . File operations -- RandomAccessFile Each instance of is used to represent a file or directory in the file system package day06; ...

  6. matlab in txt file ( Contains characters and values ) Handle

    matlab  in txt file ( Contains characters and values ) Handle (2008-08-02 09:45:12) Reprint ▼ label : gossip classification : matlab And C Study Matlab File operation and reading txt file ZZ 2008-07- ...

  7. Java Study -011- Create file instance and source code

    This article source code mainly for the application Java Create the source code of the file . If there are deficiencies , Please correct me , Thank you for ! The source code for creating the file is as follows : /** * @function File operations : create a file . If the file does not exist , Then create the file directly : if ...

  8. javamail Simulate mailbox function -- Email delete - Intermediate combat 【 Message marking method 】(javamail API Email instance )

    Preface : JavaMail jar Package download address : This chapter may be about javamail The last one of them ...

  9. php Use in PHPExcel operation excel(xls) file

    Read Chinese xls.csv There will be problems with the documents , I found some information on the Internet , Find out PHPExcel The class library is easy to use , Official website address : 1. Read xls The contents of the document   The code is as follows Copy code ...

Random recommendation

  1. use Canvas Writing billiards games !!!

    Statement : This is an original article , If you want to reprint , Please indicate the source WAxes, thank you ! I had nothing to do at work yesterday , Just use Canvas I wrote a billiard game to play .... So take this game and give it a shot . Maybe for some new students canvas The people who help . Words ...

  2. Statistics of friends page - About Viewpager Medium Fragment Life cycle of

    Activity and Fragment Their theoretical life cycles Activity The life cycle of is the most classic and clear , It's not here : Fragment It's been a while since it appeared to be widely used , Its standard life cycle is only more than Activity ...

  3. Context menu items (contextMenu)---- Long press button to pop up menu item

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  4. C++ Access managed classes (C# Class library )

    1. newly build C# The class library project Airth, The new class using System; using System.Collections.Generic; using System.Linq; using System ...

  5. iMx280A Test voiceprint

    1. First of all, there should be a dynamic library for voiceprint recognition , And arm-linux-gcc The same version of . It can be used in virtual machine file Command to see the basic information of the file , adopt file Instructions , We can tell Identify the type of the file . 2. use tftp Transfer the library to the development board li ...

  6. translate 【ElasticSearch Server】 Chapter one : Start using ElasticSearch colony (4)

    stop it ElasticSearch(Shutting down ElasticSearch) Although we expect clusters ( Or node ) Run perfectly for life , We may eventually need to restart or stop it properly ( for example , maintain ). There are three ways to stop E ...

  7. mysql Automatic database backup

    You can choose to set the library to be backed up , Automatic backup compression , Automatically delete  7  Days ahead backup , Need to use  crontab  Timing execution . #!/bin/bash #  Database name to back up , Multiple databases are separated by spaces databases=(db1 ...

  8. touchesBegan: withEvent: &lt;--- with UIScrollView / UIImageView

    touchesBegan: withEvent: / touchesMoved: withEvent: / touchesEnded: withEvent: Waiting can only be UIView Capture ( If you have any questions, please point out that ...

  9. About EF Code First The impact of different modeling methods of schema on table building

    I'm studying today EF Code First In mode , I found some interesting questions , Questions as follows : 1. When writing play entities , Do not specify any primary key constraints ,EF I'll find the one that looks like Id Of , Then set it as the primary key , The verification code is as follows : //User class cla ...

  10. ArcGIS API for JavaScript 4.2 Learning notes [6] goTo() Map animation

    This is an interesting example , But the example is more complicated , There's a lot to look up API, I'll explain the key classes and properties at the end of the article . Also found a very interesting thing : There seems to be reptiles in the blog Garden , I 4 Issue No. blogs,5 It's Baidu and google search ...