Click here to Skip to main content
6,295,667 members and growing! (17,126 online)
Email Password   helpLost your password?
Languages » C# » Utilities     Intermediate

Advanced MIME Parser/Creator/Editor

By Ivar Lumi

An advanced MIME parser/creator/editor application.
C#, Windows, .NET 1.1VS.NET2003, Dev
Posted:5 Oct 2005
Views:98,630
Bookmarked:67 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
44 votes for this article.
Popularity: 7.83 Rating: 4.76 out of 5

1

2
2 votes, 4.5%
3
5 votes, 11.4%
4
37 votes, 84.1%
5

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


Member

Location: Estonia Estonia

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 228 (Total in Forum: 228) (Refresh)FirstPrevNext
GeneralCould 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  
GeneralRe: 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  
AnswerRe: Lumisoft.Net failed to Parse PinmemberIvar Lumi20:54 14 Jun '09  
GeneralThe latest code PinmemberSarif Bin Ishak18:42 12 Feb '09  
GeneralRe: The latest code PinmemberIvar Lumi21:18 12 Feb '09  
GeneralRe: The latest code PinmemberSarif Bin Ishak23:41 12 Feb '09  
GeneralRe: The latest code PinmemberDuncanWhoCares7:54 9 Jun '09  
QuestionSomething is wrong the way we attach the file PinmemberSarif Bin Ishak18:35 11 Feb '09  
GeneralHow to attach JPG file and parse it PinmemberSarif Bin Ishak8:09 11 Feb '09  
GeneralHow to convert "Mail_Message" to byte array PinmemberSarif Bin Ishak17:11 10 Feb '09  
GeneralRe: How to convert "Mail_Message" to byte array PinmemberIvar Lumi1:19 11 Feb '09  
GeneralNew help page - step by step for the new lib PinmemberSarif Bin Ishak22:22 9 Feb '09  
GeneralRe: New help page - step by step for the new lib PinmemberIvar Lumi22:57 9 Feb '09  
GeneralStatus of new development? Pinmember3choBoomer10:42 23 Jan '09  
GeneralRe: Status of new development? PinmemberIvar Lumi21:32 23 Jan '09  
GeneralGreat work! PinmemberJohanD12:03 29 Oct '08  
GeneralRe: Great work! PinmemberIvar Lumi6:20 30 Oct '08  
GeneralUsing the new or old code? Pinmemberrichardwhitehead6:04 20 Oct '08  
GeneralRe: Using the new or old code? PinmemberIvar Lumi19:58 20 Oct '08  
GeneralTime conversion issue Pinmemberrichardwhitehead5:59 20 Oct '08  
GeneralRe: Time conversion issue PinmemberIvar Lumi20:01 20 Oct '08  
GeneralRe: Time conversion issue Pinmemberrichardwhitehead22:31 20 Oct '08  
QuestionA minor issue at ParseRfc2822DateTime Pinmemberpcyuen21:27 16 Oct '08  
AnswerRe: A minor issue at ParseRfc2822DateTime PinmemberIvar Lumi21:41 16 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Oct 2005
Editor: Smitha Vijayan
Copyright 2005 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project