Click here to Skip to main content
14,843,569 members
Articles / Programming Languages / C#
Article
Posted 5 Oct 2005

Stats

876.9K 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:

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

Share

About the Author

Ivar Lumi
Estonia Estonia
No Biography provided

Comments and Discussions

 
GeneralRe: Bug report Pin
haqwin20-Apr-06 23:08
Memberhaqwin20-Apr-06 23:08 
GeneralRe: Bug report Pin
haqwin23-Apr-06 22:35
Memberhaqwin23-Apr-06 22:35 
GeneralCan't send .eml via IIS Virtual SMTP Server Pin
Jinxter29-Mar-06 2:54
MemberJinxter29-Mar-06 2:54 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Ivar Lumi29-Mar-06 18:56
MemberIvar Lumi29-Mar-06 18:56 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Jinxter29-Mar-06 21:20
MemberJinxter29-Mar-06 21:20 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Ivar Lumi29-Mar-06 21:25
MemberIvar Lumi29-Mar-06 21:25 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Jinxter29-Mar-06 22:48
MemberJinxter29-Mar-06 22:48 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Ivar Lumi29-Mar-06 22:49
MemberIvar Lumi29-Mar-06 22:49 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Jinxter30-Mar-06 1:14
MemberJinxter30-Mar-06 1:14 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Ivar Lumi30-Mar-06 2:34
MemberIvar Lumi30-Mar-06 2:34 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Jinxter31-Mar-06 0:52
MemberJinxter31-Mar-06 0:52 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Ivar Lumi31-Mar-06 0:59
MemberIvar Lumi31-Mar-06 0:59 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Jinxter31-Mar-06 1:20
MemberJinxter31-Mar-06 1:20 
GeneralRe: Can't send .eml via IIS Virtual SMTP Server Pin
Ivar Lumi31-Mar-06 4:52
MemberIvar Lumi31-Mar-06 4:52 
QuestionA little question? Pin
ddsw041125-Mar-06 23:48
Memberddsw041125-Mar-06 23:48 
AnswerRe: A little question? Pin
Ivar Lumi26-Mar-06 1:19
MemberIvar Lumi26-Mar-06 1:19 
GeneralRe: A little question? Pin
ddsw041126-Mar-06 21:55
Memberddsw041126-Mar-06 21:55 
QuestionSigning a mime message. Pin
ovidius728-Feb-06 3:55
Memberovidius728-Feb-06 3:55 
AnswerRe: Signing a mime message. Pin
Ivar Lumi8-Feb-06 4:36
MemberIvar Lumi8-Feb-06 4:36 
GeneralRe: Signing a mime message. Pin
m0sa9-Dec-09 7:34
Memberm0sa9-Dec-09 7:34 
GeneralRe: Signing a mime message. Pin
Ivar Lumi9-Dec-09 7:59
MemberIvar Lumi9-Dec-09 7:59 
GeneralRe: Signing a mime message. [modified] Pin
m0sa9-Dec-09 8:37
Memberm0sa9-Dec-09 8:37 
GeneralC++ version Pin
hongdong26-Jan-06 13:43
Memberhongdong26-Jan-06 13:43 
GeneralRe: C++ version Pin
Ivar Lumi26-Jan-06 19:46
MemberIvar Lumi26-Jan-06 19:46 
GeneralRe: C++ version Pin
hongdong26-Jan-06 21:24
Memberhongdong26-Jan-06 21:24 

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.