How To Write &Amp; Read Messages From Thunderbird Mail Storage?}

How to Write & Read Messages from Thunderbird Mail Storage?

by

Isabela Robbins

From the last decade or so, businesses are making use of third-party components to read, write as well as manage emails. Such software components allow you to manipulate emails using SMTP, POP3, IMAP & MS Exchange Servers and these solutions have become critically important for developers. Such top-rated components have been introduced in the market by Aspose and are available for multiple developer platforms such as .NET, Java and SharePoint. Aspose.Email for .NET, Java and SharePoint are individual components which make it easy to work with HTML or plain text emails and its attachments. It also allows developers to work against SMTP, POP, FTP and Microsoft Exchange servers. Aspose.Email makes it easy to manage and manipulate emails that come in through the Microsoft Outlook program or Thunderbird Mail storage.

With Aspose.Email at hand, you can write as well as read email messages and perform many activities with those messages. For .NET platform, it provides a collection of components for working with email from within ASP.NET web applications, web services or Windows applications. It allows connection to POP3 and IMAP email servers, list and download messages locally. Support for the IMAP protocol includes authentication, create, delete, select, query folders, get, delete and save messages, change message flags and basic IMAP commands. This particular software component also allows you to read as well as write emails using Thunderbird mail storage.

Since Mozilla Thunderbird is an open source, cross-platform email client, it stores emails in its own file structure while allowing Aspose.Email to work with this email storage structures. The following code snippets for C# show how to read and write messages from Thunderbird:

To Read Messages from Thunderbird

To read the messages from Thunderbird email storage, you are required to follow these steps:

1. Open the Thunderbird’s storage file in FileStream.

2. Create an instance of the MboxrdStorageReader class and pass this stream to the 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.

// Open the storage file with FileStream

[youtube]http://www.youtube.com/watch?v=8h_IcLn4JSg[/youtube]

FileStream stream = new FileStream(@”Thunderbird\inbox”, FileMode.Open, FileAccess.Read);

// Create an instance of the 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 the next message

message = reader.ReadNextMessage();

}

// Close the streams

reader.Dispose();

stream.Close();

To Write New Messages to Thunderbird

To write messages:

1. Open the Thunderbird storage file in FileStream.

2. Create an instance of the MboxrdStorageWriter class and pass this stream to the constructor.

3. Prepare a new message using the MailMessage class.

4. Call the WriteMessage() method and pass the MailMessage instance to add the message to Thunderbird storage.

5. Close all streams.

// Open the Thunderbird storage file in a writable FileStream

FileStream stream = new FileStream(@”Thunderbird\inbox”, FileMode.Open, FileAccess.Write);

// Initialize MboxStorageWriter and pass the above stream to it

MboxrdStorageWriter writer = new MboxrdStorageWriter(stream, false);

// Prepare a new message using the MailMessage class

MailMessage message = new MailMessage(“from@domain.com”, “to@domain.com”, “added 1 from Aspose.Email”, “added from Aspose.Email”);

// Add this message to storage

writer.WriteMessage(message);

// Close all related streams

writer.Dispose();

stream.Close();

Aspose

is a leading vendor of .NET, Java and SharePoint development components, and rendering extensions for platforms such as Microsoft SQL Server Reporting Services and JasperReports. Aspose’s core focus is to offer the most complete and powerful set of file management products on the market. Aspose products support some of the most popular file formats in business, including: Word documents, Excel spreadsheets, PowerPoint presentations, PDF documents, Microsoft Visio diagrams and Microsoft Project files. We also offer OCR and image manipulation tools.

Article Source:

eArticlesOnline.com

}