Click here to Skip to main content
Licence 
First Posted 5 Oct 2005
Views 224,876
Downloads 2,928
Bookmarked 101 times

Advanced MIME Parser/Creator/Editor

By Ivar Lumi | 5 Oct 2005
An advanced MIME parser/creator/editor application.

1

2
2 votes, 3.2%
3
5 votes, 8.1%
4
55 votes, 88.7%
5
4.91/5 - 62 votes
2 removed
μ 4.80, σa 0.90 [?]

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

About the Author

Ivar Lumi



Estonia Estonia

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionhow to save attachment from mail to disk Pinmemberano&gete3:23 3 Oct '09  
AnswerRe: how to save attachment from mail to disk PinmemberIvar Lumi20:53 3 Oct '09  
GeneralRe: how to save attachment from mail to disk PinmemberRajdipS4:01 29 Apr '10  
GeneralRe: how to save attachment from mail to disk PinmemberIvar Lumi4:37 29 Apr '10  
GeneralRe: how to save attachment from mail to disk PinmemberRajdipS6:09 29 Apr '10  
GeneralRe: how to save attachment from mail to disk PinmemberRajdipS5:03 29 Apr '10  
GeneralParsing date error PinmemberElvandar23:26 1 Oct '09  
Hi Ivar!
 
I have a little problem...I was trying to parse an incoming POP3 e-mail:
 
POP3_ClientMessage PopMessage = Pop.Messages [i];
Mail_Message MailMessage = Mail_Message.ParseFromByte (PopMessage.MessageToByte ());
 
My problem is that the mail server used doesn't comply to RFC 2822 to format date-time field, it is "Date: 30 Sep 2009 17:46:22" instead of "Date: 30 Sep 2009 17:46:22 +0200", so your parser throws a ParseException...is there a way to avoid parsing of the time zone field? Without recompiling your library and without making a workaround modifying the "Date: " field and adding the field...
 
By the way, you made a great work with this library, it is very useful!!! Smile | :)
GeneralRe: Parsing date error PinmemberIvar Lumi23:51 1 Oct '09  
NewsRe: Parsing date error [modified] PinmemberElvandar0:20 2 Oct '09  
GeneralRe: Parsing date error PinmemberIvar Lumi1:18 2 Oct '09  
GeneralRe: Parsing date error PinmemberElvandar1:25 2 Oct '09  
Questionlatest version, mime parsing PinmemberMember 27431560:21 29 Sep '09  
AnswerRe: latest version, mime parsing PinmemberIvar Lumi0:51 29 Sep '09  
GeneralNice job PinmemberSteve Trefethen22:43 3 Sep '09  
GeneralRe: Nice job PinmemberIvar Lumi2:21 4 Sep '09  
QuestionWhat about an eml inside an eml? PinmemberBroxCJ2:22 11 Aug '09  
AnswerRe: What about an eml inside an eml? PinmemberIvar Lumi6:40 11 Aug '09  
GeneralRe: What about an eml inside an eml? PinmemberBroxCJ23:03 11 Aug '09  
GeneralChange from Singlepart to multipart and preserve attachment PinmemberBman286:12 16 Jul '09  
GeneralRe: Change from Singlepart to multipart and preserve attachment PinmemberIvar Lumi8:12 16 Jul '09  
GeneralRe: Change from Singlepart to multipart and preserve attachment PinmemberBman289:25 16 Jul '09  
GeneralRe: Change from Singlepart to multipart and preserve attachment PinmemberIvar Lumi21:29 16 Jul '09  
QuestionCould you please write a simple sample code that reads a eml file and load it on a MailMessage class of .net framework? Pinmemberevald800:46 22 Jun '09  
AnswerRe: Could you please write a simple sample code that reads a eml file and load it on a MailMessage class of .net framework? PinmemberIvar Lumi4:34 22 Jun '09  
QuestionLumisoft.Net failed to Parse PinmemberDharmeshChauhan4:21 12 Jun '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120210.1 | Last Updated 5 Oct 2005
Article Copyright 2005 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid