Check out the sample code below to see just how easy it is to use the Parse
component of EasyMail .Net Edition to parse MIME messages. But don't let
the ease of use fool you; the Parse component exposes every part of
the message and contains many feature rich methods to help you easily get the
message data into your application. The sample code on this page
demonstrates the most basic features of the Parse component.
Be sure to click on the "Other Samples" tab to find more advanced samples.
| Sample Notes | | This sample reads a message from disk as stream, parses it, displays the message subject, first body part and then the filename of each attachment. This is a very simple 'boiled down' example, but it clearly shows you how things are done. If you are downloading a message with the POP3 or IMAP4 components, you can pass the downloaded stream right into the parse method, or even into the EMailMessage class constructor to easily parse downloaded messages in memory. |
FileStream fileStream = File.OpenRead("c:\\msg.eml"); EmailMessage msg = new EmailMessage(fileStream);
Console.WriteLine(msg.Subject); Console.WriteLine(msg.BodyParts[1].BodyText);
AttachmentCollection attachments = msg.Attachments; foreach (Attachment attachment in attachments) { Console.WriteLine(attachment.Filename);
attachment.Save("c:\\attachment.dat", true); }
|