Click here to Skip to main content
12,635,662 members (25,710 online)
Click here to Skip to main content
Add your own
alternative version

Stats

658.4K views
6.9K downloads
115 bookmarked
Posted

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

 
QuestionGreat job! Thank you so much but... Pin
ATXOOM5-Nov-11 7:12
memberATXOOM5-Nov-11 7:12 
AnswerRe: Great job! Thank you so much but... Pin
Ivar Lumi5-Nov-11 22:13
memberIvar Lumi5-Nov-11 22:13 
Generalstrange first line in saved email (*.eml) Pin
mbican4-Oct-11 10:48
membermbican4-Oct-11 10:48 
GeneralRe: strange first line in saved email (*.eml) Pin
Ivar Lumi5-Nov-11 22:12
memberIvar Lumi5-Nov-11 22:12 
Suggestionadd support for linux line endings Pin
mbican4-Oct-11 10:34
membermbican4-Oct-11 10:34 
GeneralRe: add support for linux line endings Pin
Ivar Lumi4-Oct-11 20:00
memberIvar Lumi4-Oct-11 20:00 
GeneralRe: add support for linux line endings Pin
mbican4-Oct-11 20:34
membermbican4-Oct-11 20:34 
Bugmime as attachment - Mime.Attachments[0].data is null Pin
mbican4-Oct-11 10:26
membermbican4-Oct-11 10:26 
GeneralRe: mime as attachment - Mime.Attachments[0].data is null Pin
Ivar Lumi4-Oct-11 19:59
memberIvar Lumi4-Oct-11 19:59 
QuestionExtract Attachment Pin
TOOGuy14-Mar-11 12:55
memberTOOGuy14-Mar-11 12:55 
AnswerRe: Extract Attachment Pin
Ivar Lumi14-Mar-11 21:50
memberIvar Lumi14-Mar-11 21:50 
GeneralRe: Extract Attachment Pin
TOOGuy16-Mar-11 6:16
memberTOOGuy16-Mar-11 6:16 
General100% CPU usage when sending mails Pin
jozefkarton30-Dec-10 10:49
memberjozefkarton30-Dec-10 10:49 
GeneralRe: 100% CPU usage when sending mails Pin
Ivar Lumi30-Dec-10 20:54
memberIvar Lumi30-Dec-10 20:54 
GeneralRe: 100% CPU usage when sending mails Pin
jozefkarton31-Dec-10 1:27
memberjozefkarton31-Dec-10 1:27 
GeneralRe: 100% CPU usage when sending mails Pin
Ivar Lumi31-Dec-10 1:32
memberIvar Lumi31-Dec-10 1:32 
GeneralRe: 100% CPU usage when sending mails Pin
jozefkarton31-Dec-10 1:59
memberjozefkarton31-Dec-10 1:59 
GeneralRe: 100% CPU usage when sending mails Pin
Ivar Lumi31-Dec-10 2:35
memberIvar Lumi31-Dec-10 2:35 
GeneralRe: 100% CPU usage when sending mails Pin
jozefkarton31-Dec-10 3:06
memberjozefkarton31-Dec-10 3:06 
GeneralRe: 100% CPU usage when sending mails Pin
Ivar Lumi31-Dec-10 5:56
memberIvar Lumi31-Dec-10 5:56 
GeneralRe: 100% CPU usage when sending mails Pin
jozefkarton31-Dec-10 7:32
memberjozefkarton31-Dec-10 7:32 
GeneralRe: 100% CPU usage when sending mails Pin
Ivar Lumi31-Dec-10 8:10
memberIvar Lumi31-Dec-10 8:10 
GeneralBCC missing from Mail_Message.ParseFromFile() Pin
Brad Bruce17-Dec-10 15:16
memberBrad Bruce17-Dec-10 15:16 
GeneralRe: BCC missing from Mail_Message.ParseFromFile() Pin
Ivar Lumi17-Dec-10 21:22
memberIvar Lumi17-Dec-10 21:22 
GeneralRe: BCC missing from Mail_Message.ParseFromFile() [modified] Pin
Brad Bruce18-Dec-10 3:14
memberBrad Bruce18-Dec-10 3:14 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 5 Oct 2005
Article Copyright 2005 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid