Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 20, 2022 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/6838570e1c206d16fa6053262c7d3fbb to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6838570e1c206d16fa6053262c7d3fbb to your computer and use it in GitHub Desktop.
Write and Read Messages on Thunderbird Storage in C# .NET
// Open the storage file with FileStream
FileStream stream = new FileStream("ExampleMbox.mbox", 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", SaveOptions.DefaultEml);
message.Save(message.Subject + ".msg", SaveOptions.DefaultMsgUnicode);
// Get the next message
message = reader.ReadNextMessage();
}
// Close the streams
reader.Dispose();
stream.Close();
// Open the storage file with FileStream
FileStream stream = new FileStream("ExampleMbox.mbox", FileMode.Open, FileAccess.Write);
// Initialize MboxStorageWriter and pass the 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", Guid.NewGuid().ToString(), "added from Aspose.Email");
message.IsDraft = false;
// Add this message to storage
writer.WriteMessage(message);
// Close all related streams
writer.Dispose();
stream.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment