How to parse a raw email string into a System.Net.Mail.MailMessage object?

I wrote a program in C# that connects to a POP Server and retrieves raw strings of email messages from a server using the POP3 RETR . Since the email message received by the program is in text format with all the headers and body of the message in the same, it is too difficult to extract each header and body of the message from the raw string.

Can someone tell me a solution with which I can parse all the raw text into a System.Net.Mail.MailMessage object?

The following is an example of a raw string:

 +OK 1281 octets Return-Path: < sample@test.in > Delivered-To: samplenet-sample: in-sample2@test.in X-Envelope-To: sample2@test.in Received: (qmail 53856 invoked from network); 22 Sep 2012 06:11:46 -0000 Received: from mailwash18.pair.com (66.39.2.18) MIME-Version: 1.0 From: "Deepu" < sample@test.in > To: sample2@test.in Date: 22 Sep 2012 11:41:39 +0530 Subject: TEST Subject Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-Id: < 20120922061146.2975C11554D@mailwash18.pair.com > TEST Body . 
+4
source share
2 answers

After a little research, I was able to find the OpenPop.Net open source library, which has almost all the short methods of communicating with the POP3 server.

This is very useful as it completes the raw email message to the strongly typed Message object, and parts of the email message, including any attachments, can also be accessed separately. This is really awesome!

Here's a link:

http://hpop.sourceforge.net/

+6
source

I am currently learning the same thing. This article contains a method for parsing an email string for a custom email object:

http://dotnetslackers.com/articles/aspnet/Creating-a-Dynamic-Email-Drop-Box-Part2.aspx

He needs a lot of work to be able to correctly analyze all emails. For example, the format of the sent date field may be different, and this script only catches one format. But this project is a good start.

+1
source

Source: https://habr.com/ru/post/1435645/


All Articles