Click here to Skip to main content
14,696,222 members
Articles » Languages » C# » Utilities
Article
Posted 5 Oct 2005

Stats

865.7K views
7.6K downloads
116 bookmarked

Advanced MIME Parser/Creator/Editor

Rate me:
Please Sign up or sign in to vote.
4.91/5 (65 votes)
5 Oct 2005
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:

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

Creating a new simple message:

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:

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

Share

About the Author

Ivar Lumi
Estonia Estonia
No Biography provided

Comments and Discussions

 
GeneralRe: BCC missing from Mail_Message.ParseFromFile() Pin
Ivar Lumi19-Dec-10 20:59
MemberIvar Lumi19-Dec-10 20:59 
GeneralRe: BCC missing from Mail_Message.ParseFromFile() Pin
Brad Bruce20-Dec-10 1:34
MemberBrad Bruce20-Dec-10 1:34 
GeneralRe: BCC missing from Mail_Message.ParseFromFile() Pin
Ivar Lumi20-Dec-10 3:23
MemberIvar Lumi20-Dec-10 3:23 
GeneralRe: BCC missing from Mail_Message.ParseFromFile() Pin
Brad Bruce20-Dec-10 4:46
MemberBrad Bruce20-Dec-10 4:46 
GeneralRe: BCC missing from Mail_Message.ParseFromFile() [modified] Pin
bertkid12-Jan-12 5:08
Memberbertkid12-Jan-12 5:08 
GeneralSERVER_FALURE when connecting by SmtpClientEx Pin
jozefkarton17-Dec-10 12:13
Memberjozefkarton17-Dec-10 12:13 
GeneralRe: SERVER_FALURE when connecting by SmtpClientEx Pin
Ivar Lumi17-Dec-10 21:16
MemberIvar Lumi17-Dec-10 21:16 
GeneralRe: SERVER_FALURE when connecting by SmtpClientEx Pin
jozefkarton19-Dec-10 12:21
Memberjozefkarton19-Dec-10 12:21 
GeneralRe: SERVER_FALURE when connecting by SmtpClientEx Pin
Ivar Lumi19-Dec-10 21:01
MemberIvar Lumi19-Dec-10 21:01 
GeneralRe: SERVER_FALURE when connecting by SmtpClientEx Pin
jozefkarton20-Dec-10 12:18
Memberjozefkarton20-Dec-10 12:18 
GeneralRe: SERVER_FALURE when connecting by SmtpClientEx Pin
Ivar Lumi20-Dec-10 22:10
MemberIvar Lumi20-Dec-10 22:10 
GeneralRe: SERVER_FALURE when connecting by SmtpClientEx Pin
jozefkarton22-Dec-10 8:54
Memberjozefkarton22-Dec-10 8:54 
GeneralRe: SERVER_FALURE when connecting by SmtpClientEx Pin
Ivar Lumi22-Dec-10 9:06
MemberIvar Lumi22-Dec-10 9:06 
GeneralMy vote of 5 Pin
joni_555-Dec-10 4:47
Memberjoni_555-Dec-10 4:47 
QuestionCan i get the percent of downloaded attachment? Pin
joni_554-Dec-10 12:17
Memberjoni_554-Dec-10 12:17 
AnswerRe: Can i get the percent of downloaded attachment? Pin
Ivar Lumi5-Dec-10 2:38
MemberIvar Lumi5-Dec-10 2:38 
QuestionThe download allows building of the dll. Is there a test application? Pin
Gary Dryden4-Dec-10 9:55
MemberGary Dryden4-Dec-10 9:55 
AnswerRe: The download allows building of the dll. Is there a test application? Pin
Ivar Lumi5-Dec-10 2:36
MemberIvar Lumi5-Dec-10 2:36 
QuestionRe: The download allows building of the dll. Is there a test application? Pin
Gary Dryden5-Dec-10 4:50
MemberGary Dryden5-Dec-10 4:50 
AnswerRe: The download allows building of the dll. Is there a test application? Pin
Ivar Lumi5-Dec-10 20:57
MemberIvar Lumi5-Dec-10 20:57 
QuestionEmbedded pictures in RTF? Pin
Marijan Rengel28-Nov-10 0:14
MemberMarijan Rengel28-Nov-10 0:14 
AnswerRe: Embedded pictures in RTF? Pin
Ivar Lumi28-Nov-10 6:29
MemberIvar Lumi28-Nov-10 6:29 
QuestionMime Message Body parser for windows mobile 6 Pin
ChincoCodus3-Nov-10 1:10
MemberChincoCodus3-Nov-10 1:10 
AnswerRe: Mime Message Body parser for windows mobile 6 Pin
Ivar Lumi3-Nov-10 2:07
MemberIvar Lumi3-Nov-10 2:07 
GeneralLicense question Pin
Yaron Naveh25-Oct-10 9:17
MemberYaron Naveh25-Oct-10 9:17 

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.