Click here to Skip to main content
15,861,168 members
Articles / Programming Languages / C#
Article

Advanced MIME Parser/Creator/Editor

Rate me:
Please Sign up or sign in to vote.
4.91/5 (66 votes)
5 Oct 2005 984.6K   7.7K   116   322
An advanced MIME parser/creator/editor application.

Introduction

This article provides an advanced MIME editor. You can use it for parsing email messages, changing messages and for creating new email messages. It supports creation of complex messages with nested MIME entities. For more info, see help file: LumiSoft.Net.Mime namespace.

Message examples

Simple message:

//--- Beginning of message
From: sender@domain.com
To: recipient@domain.com
Subject: Message subject.
Content-Type: text/plain

Message body text. Bla blaa
blaa,blaa.
//--- End of message

In simple message, the MainEntity is the whole message.

Message with attachments:

//--- Beginning of message
From: sender@domain.com
To: recipient@domain.com
Subject: Message subject.
Content-Type: multipart/mixed; boundary="multipart_mixed"

--multipart_mixed    /* text entity */
Content-Type: text/plain

Message body text. Bla blaa
blaa,blaa.
--multipart_mixed    /* attachment entity */
Content-Type: application/octet-stream

attachment_data
--multipart_mixed--
//--- End of message

Here MainEntity is the multipart_mixed entity, and the text and attachment entities are child entities of MainEntity.

Using the code

Parsing example:

C#
Mime m = Mime.Parse("message.eml");
// Do your stuff with mime

Creating a new simple message:

C#
Mime m = new Mime();
MimeEntity mainEntity = m.MainEntity;
// Force to create From: header field
mainEntity.From = new AddressList();
mainEntity.From.Add(new MailboxAddress("dispaly name","user@domain.com"));
// Force to create To: header field
mainEntity.To = new AddressList();
mainEntity.To.Add(new MailboxAddress("dispaly name","user@domain.com"));
mainEntity.Subject = "subject";
mainEntity.ContentType = MediaType_enum.Text_plain;
mainEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
mainEntity.DataText = "Message body text.";

m.ToFile("message.eml");

Creating a message with text and attachments:

C#
Mime m = new Mime();
MimeEntity mainEntity = m.MainEntity;
// Force to create From: header field
mainEntity.From = new AddressList();
mainEntity.From.Add(new MailboxAddress("dispaly name","user@domain.com"));
// Force to create To: header field
mainEntity.To = new AddressList();
mainEntity.To.Add(new MailboxAddress("dispaly name","user@domain.com"));
mainEntity.Subject = "subject";
mainEntity.ContentType = MediaType_enum.Multipart_mixed;

MimeEntity textEntity = mainEntity.ChildEntities.Add();
textEntity.ContentType = MediaType_enum.Text_plain;
textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
textEntity.DataText = "Message body text.";

MimeEntity attachmentEntity = mainEntity.ChildEntities.Add();
attachmentEntity.ContentType = MediaType_enum.Application_octet_stream;
attachmentEntity.ContentDisposition = ContentDisposition_enum.Attachment;
attachmentEntity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;
attachmentEntity.ContentDisposition_FileName = "yourfile.xxx";
attachmentEntity.DataFromFile("yourfile.xxx");
// or
attachmentEntity.Data = your_attachment_data;

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Thanks Pin
Ivar Lumi12-Apr-07 2:38
Ivar Lumi12-Apr-07 2:38 
GeneralInformation Pin
guerriero832-Mar-07 23:54
guerriero832-Mar-07 23:54 
GeneralRe: Information Pin
Ivar Lumi3-Mar-07 0:30
Ivar Lumi3-Mar-07 0:30 
GeneralRe: CDecode() bugs, break subject when mixed code. Pin
Ivar Lumi10-Dec-06 20:43
Ivar Lumi10-Dec-06 20:43 
GeneralMinor ParseDate bug Pin
williaml19-Nov-06 11:25
williaml19-Nov-06 11:25 
GeneralRe: Minor ParseDate bug Pin
Ivar Lumi19-Nov-06 19:49
Ivar Lumi19-Nov-06 19:49 
GeneralPleasantly Surprised Pin
Bob Hartman26-Sep-06 2:58
Bob Hartman26-Sep-06 2:58 
GeneralRe: Pleasantly Surprised Pin
Ivar Lumi26-Sep-06 3:04
Ivar Lumi26-Sep-06 3:04 
Hi,

I'll try do my best.

I opened forum:
http://www.lumisoft.ee/Forum/[^]

And latest downloads are in:
http://www.lumisoft.ee/lswww/download/downloads/[^]
GeneralYou can get lates from: Pin
Ivar Lumi30-Aug-06 0:03
Ivar Lumi30-Aug-06 0:03 
GeneralRe: You can get lates from: Pin
Binkle@JAM5-Sep-06 3:18
Binkle@JAM5-Sep-06 3:18 
QuestionBroken links in .eml files Pin
Jinxter28-Aug-06 20:56
Jinxter28-Aug-06 20:56 
AnswerRe: Broken links in .eml files Pin
Ivar Lumi28-Aug-06 21:04
Ivar Lumi28-Aug-06 21:04 
GeneralRe: Broken links in .eml files Pin
Jinxter28-Aug-06 21:25
Jinxter28-Aug-06 21:25 
GeneralRe: Broken links in .eml files Pin
Ivar Lumi28-Aug-06 21:58
Ivar Lumi28-Aug-06 21:58 
GeneralThank you for your library Pin
Nicola Ahrens25-Aug-06 14:23
Nicola Ahrens25-Aug-06 14:23 
GeneralRe: Thank you for your library Pin
Ivar Lumi26-Aug-06 2:22
Ivar Lumi26-Aug-06 2:22 
GeneralRe: Thank you for your library Pin
Ivar Lumi30-Aug-06 0:00
Ivar Lumi30-Aug-06 0:00 
GeneralRead Receipts Pin
Yazeed hs23-Jul-06 23:10
Yazeed hs23-Jul-06 23:10 
GeneralRe: Read Receipts Pin
Ivar Lumi23-Jul-06 23:58
Ivar Lumi23-Jul-06 23:58 
GeneralRe: Read Receipts Pin
Yazeed hs24-Jul-06 2:45
Yazeed hs24-Jul-06 2:45 
GeneralRe: Read Receipts Pin
Ivar Lumi24-Jul-06 3:30
Ivar Lumi24-Jul-06 3:30 
GeneralRe: Read Receipts Pin
Yazeed hs25-Jul-06 1:33
Yazeed hs25-Jul-06 1:33 
GeneralRe: Read Receipts Pin
Ivar Lumi25-Jul-06 1:41
Ivar Lumi25-Jul-06 1:41 
GeneralRe: Read Receipts Pin
Yazeed hs26-Jul-06 4:56
Yazeed hs26-Jul-06 4:56 
GeneralJust Amazing Pin
Gonzalo Brusella13-Jul-06 4:03
Gonzalo Brusella13-Jul-06 4:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.