Home > Code > General > Read Email Messages from Thunderbird Mail Storage Using Aspose.Email

Read Email Messages from Thunderbird Mail Storage Using Aspose.Email

by sher azam   on Apr 17, 2012   Category: General   |  Views: 2482    |  Points: 25   |  Gold 


This technical tip shows how to read messages from Thunderbird Mail Storage. Below steps are required to read the messages
1. Open the Thunderbird’s storage file in FileStream
2. Create an instance of MboxrdStorageReader class and pass the above stream to it’s constructor
3. Call ReadNextMessage() to get the first message
4. Use the same ReadNextMessage() in a while loop to read all the messages
5. Close all the streams
Below is the code snippet to read all the messages from Thunderbird’s mail storage:

[C#]

// Open the storage file with FileStream
FileStream stream = new FileStream(@"Thunderbird\inbox", FileMode.Open, FileAccess.Read);
// Create an instance of MboxrdStorageReader class and pass the stream
MboxrdStorageReader reader = new MboxrdStorageReader(stream, false);
// Start reading messages
MailMessage message = reader.ReadNextMessage();

// Read all messages in a loop
while (message != null)
{
// Manipulate message - show contents
Console.WriteLine("Subject: " + message.Subject);
// Save this message in EML or MSG format
message.Save(message.Subject + ".eml", MailMessageSaveType.EmlFormat);
message.Save(message.Subject + ".msg", MailMessageSaveType.OutlookMessageFormatUnicode);

// get next message
message = reader.ReadNextMessage();
}

// Close the streams
reader.Dispose();
stream.Close();


[VB.NET]

' Open the storage file with FileStream
Dim stream As FileStream = New FileStream("Thunderbird\inbox", FileMode.Open, FileAccess.Read)
' Create an instance of MboxrdStorageReader class and pass the stream
Dim reader As MboxrdStorageReader = New MboxrdStorageReader(stream, False)
' Start reading messages
Dim message As MailMessage = reader.ReadNextMessage()

' Read all messages in a loop
Do While Not message Is Nothing
' Manipulate message - show contents
Console.WriteLine("Subject: " & message.Subject)
' Save this message in EML or MSG format
message.Save(message.Subject & ".eml", MailMessageSaveType.EmlFormat)
message.Save(message.Subject & ".msg", MailMessageSaveType.OutlookMessageFormatUnicode)

' get next message
message = reader.ReadNextMessage()
Loop

' Close the streams
reader.Dispose()
stream.Close()


Overview: Aspose.Email for .NET

Aspose.Email for .NET is a set of components allowing developers to easily implement email functionality within their ASP.NET web applications, web services & Windows applications. It Supports Outlook PST, EML, MSG & MHT formats. It allows developers to work with SMTP, POP3, FTP & MS Exchange servers. It supports mail merge, iCalendar, customized header & body, header information, embedded files, Twitter & many more. It makes it easy to work with HTML or plain text emails & their attachments.

More about Aspose.Email for .NET

- Homepage of Aspose.Email for .NET: http://www.aspose.com/categories/.net-components/aspose.email-for-.net/default.aspx

- Download Aspose.Email for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.email-for-.net/default.aspx

- More Technical Tips by Aspose.Email for .NET: http://www.aspose.com/documentation/.net-components/aspose.email-for-.net/knowledge-base.html

Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
http://www.aspose.com/
sales@aspose.com
Phone: 888.277.6734
Fax: 866.810.9465




Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts