Writing MBOX Files
Contents
[
Hide
]
Write MBOX Files
If you need to create or update MBOX files programmatically, use Aspose.Email MboxrdStorageWriter class which allows you to write new messages to Thunderbird mail storage file.
The following code snippet shows you how to write messages to Thunderbird mail storage:
- Open the Thunderbird storage file in FileStream.
- Create an instance of the MboxrdStorageWriter class and pass the above stream to the constructor.
- Prepare a new message using the MailMessage class.
- Call the WriteMessage() method and pass the above MailMessage instance to add the message to Thunderbird storage.
- Close all streams.
// Open the storage file with FileStream
var stream = new FileStream(dataDir + "ExampleMbox.mbox", FileMode.Open, FileAccess.Write);
// Initialize MboxStorageWriter and pass the above stream to it
var writer = new MboxrdStorageWriter(stream, false);
// Prepare a new message using the MailMessage class
var 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();