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

Stats

865.8K 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: problem with attachment as eml Pin
Ivar Lumi29-May-08 1:41
MemberIvar Lumi29-May-08 1:41 
General.msg file as an attachment in the email Pin
gokul7819-May-08 12:27
Membergokul7819-May-08 12:27 
GeneralRe: .msg file as an attachment in the email Pin
Ivar Lumi19-May-08 20:40
MemberIvar Lumi19-May-08 20:40 
GeneralTrying to solve a performance issue Pin
Member 107367114-May-08 12:43
MemberMember 107367114-May-08 12:43 
GeneralRe: Trying to solve a performance issue Pin
Member 107367114-May-08 14:46
MemberMember 107367114-May-08 14:46 
GeneralRe: Trying to solve a performance issue Pin
Ivar Lumi14-May-08 23:00
MemberIvar Lumi14-May-08 23:00 
GeneralCouple bugs Pin
Matt Branthwaite28-Apr-08 8:40
MemberMatt Branthwaite28-Apr-08 8:40 
GeneralRe: Couple bugs Pin
Ivar Lumi28-Apr-08 20:11
MemberIvar Lumi28-Apr-08 20:11 
GeneralBASE64 attachments fail if incorrect length Pin
Fashtas18-Apr-08 15:01
MemberFashtas18-Apr-08 15:01 
GeneralRe: BASE64 attachments fail if incorrect length Pin
GARTHCJ3-Jul-08 6:50
MemberGARTHCJ3-Jul-08 6:50 
Question[Message Deleted] Pin
Anant_M16-Apr-08 5:45
MemberAnant_M16-Apr-08 5:45 
AnswerRe: Unable to parse base64 encoded eml file Pin
Anant_M16-Apr-08 6:32
MemberAnant_M16-Apr-08 6:32 
GeneralRe: Unable to parse base64 encoded eml file Pin
Ivar Lumi16-Apr-08 7:11
MemberIvar Lumi16-Apr-08 7:11 
GeneralRegarding attachment. Pin
VIPULPANCHAL14-Mar-08 6:52
MemberVIPULPANCHAL14-Mar-08 6:52 
GeneralRe: Regarding attachment. Pin
Ivar Lumi14-Mar-08 7:58
MemberIvar Lumi14-Mar-08 7:58 
GeneralFirst class Pin
i96danma16-Jan-08 12:18
Memberi96danma16-Jan-08 12:18 
GeneralRe: First class Pin
Ivar Lumi16-Jan-08 21:47
MemberIvar Lumi16-Jan-08 21:47 
GeneralVery good project! Pin
ap8212-Dec-07 5:56
Memberap8212-Dec-07 5:56 
GeneralLarge Attachments Pin
Gerhardt Landers5-Nov-07 4:28
MemberGerhardt Landers5-Nov-07 4:28 
GeneralRe: Large Attachments Pin
Ivar Lumi5-Nov-07 4:38
MemberIvar Lumi5-Nov-07 4:38 
GeneralRe: Large Attachments Pin
Gerhardt Landers5-Nov-07 21:07
MemberGerhardt Landers5-Nov-07 21:07 
GeneralRe: Large Attachments Pin
Ivar Lumi10-Nov-07 0:44
MemberIvar Lumi10-Nov-07 0:44 
QuestionProblem viewing From: email address Pin
chezy5252-Nov-07 8:26
Memberchezy5252-Nov-07 8:26 
AnswerRe: Problem viewing From: email address Pin
Ivar Lumi2-Nov-07 8:32
MemberIvar Lumi2-Nov-07 8:32 
GeneralRe: Problem viewing From: email address Pin
chezy5252-Nov-07 9:35
Memberchezy5252-Nov-07 9:35 

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.