Read the complete article on how to write and read messages from Thunderbird storage in C# .NET: https://blog.aspose.com/2022/03/19/write-and-read-messages-on-thunderbird-storage-in-csharp/
Last active
April 20, 2022 10:16
-
-
Save aspose-com-gists/6838570e1c206d16fa6053262c7d3fbb to your computer and use it in GitHub Desktop.
Write and Read Messages on Thunderbird Storage in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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