Click here to Skip to main content
13,863,013 members
Click here to Skip to main content
Add your own
alternative version

Stats

830.4K views
7.4K downloads
116 bookmarked
Posted 5 Oct 2005
Licenced

Advanced MIME Parser/Creator/Editor

, 5 Oct 2005
Rate this:
Please Sign up or sign in to vote.
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

You may also be interested in...

Comments and Discussions

 
GeneralRe: Parsing date error Pin
Ivar Lumi1-Oct-09 23:51
memberIvar Lumi1-Oct-09 23:51 
NewsRe: Parsing date error [modified] Pin
Elvandar2-Oct-09 0:20
memberElvandar2-Oct-09 0:20 
GeneralRe: Parsing date error Pin
Ivar Lumi2-Oct-09 1:18
memberIvar Lumi2-Oct-09 1:18 
GeneralRe: Parsing date error Pin
Elvandar2-Oct-09 1:25
memberElvandar2-Oct-09 1:25 
Questionlatest version, mime parsing Pin
Member 274315629-Sep-09 0:21
memberMember 274315629-Sep-09 0:21 
AnswerRe: latest version, mime parsing Pin
Ivar Lumi29-Sep-09 0:51
memberIvar Lumi29-Sep-09 0:51 
GeneralNice job Pin
Steve Trefethen3-Sep-09 22:43
memberSteve Trefethen3-Sep-09 22:43 
GeneralRe: Nice job Pin
Ivar Lumi4-Sep-09 2:21
memberIvar Lumi4-Sep-09 2:21 
Hi,

I see that you use very old version, you should use new version.
http://www.lumisoft.ee/lswww/download/downloads/[^]
QuestionWhat about an eml inside an eml? Pin
BroxCJ11-Aug-09 2:22
memberBroxCJ11-Aug-09 2:22 
AnswerRe: What about an eml inside an eml? Pin
Ivar Lumi11-Aug-09 6:40
memberIvar Lumi11-Aug-09 6:40 
GeneralRe: What about an eml inside an eml? Pin
BroxCJ11-Aug-09 23:03
memberBroxCJ11-Aug-09 23:03 
GeneralChange from Singlepart to multipart and preserve attachment Pin
Bman2816-Jul-09 6:12
memberBman2816-Jul-09 6:12 
GeneralRe: Change from Singlepart to multipart and preserve attachment Pin
Ivar Lumi16-Jul-09 8:12
memberIvar Lumi16-Jul-09 8:12 
GeneralRe: Change from Singlepart to multipart and preserve attachment Pin
Bman2816-Jul-09 9:25
memberBman2816-Jul-09 9:25 
GeneralRe: Change from Singlepart to multipart and preserve attachment Pin
Ivar Lumi16-Jul-09 21:29
memberIvar Lumi16-Jul-09 21:29 
QuestionCould you please write a simple sample code that reads a eml file and load it on a MailMessage class of .net framework? Pin
evald8022-Jun-09 0:46
memberevald8022-Jun-09 0:46 
AnswerRe: Could you please write a simple sample code that reads a eml file and load it on a MailMessage class of .net framework? Pin
Ivar Lumi22-Jun-09 4:34
memberIvar Lumi22-Jun-09 4:34 
QuestionLumisoft.Net failed to Parse Pin
DharmeshChauhan12-Jun-09 4:21
memberDharmeshChauhan12-Jun-09 4:21 
AnswerRe: Lumisoft.Net failed to Parse Pin
Ivar Lumi14-Jun-09 20:54
memberIvar Lumi14-Jun-09 20:54 
GeneralThe latest code Pin
Sarif Bin Ishak12-Feb-09 18:42
memberSarif Bin Ishak12-Feb-09 18:42 
GeneralRe: The latest code Pin
Ivar Lumi12-Feb-09 21:18
memberIvar Lumi12-Feb-09 21:18 
GeneralRe: The latest code Pin
Sarif Bin Ishak12-Feb-09 23:41
memberSarif Bin Ishak12-Feb-09 23:41 
GeneralRe: The latest code Pin
DuncanWhoCares9-Jun-09 7:54
memberDuncanWhoCares9-Jun-09 7:54 
QuestionSomething is wrong the way we attach the file Pin
Sarif Bin Ishak11-Feb-09 18:35
memberSarif Bin Ishak11-Feb-09 18:35 
QuestionHow to attach JPG file and parse it Pin
Sarif Bin Ishak11-Feb-09 8:09
memberSarif Bin Ishak11-Feb-09 8:09 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190214.1 | Last Updated 5 Oct 2005
Article Copyright 2005 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid