MBOX ファイルの書き込み
Contents
[
Hide
]
MBOX ファイルを書き込む
プログラムで MBOX ファイルを作成または更新する必要がある場合は、Aspose.Email を使用してください MboxrdStorageWriter Thunderbird のメールストレージファイルに新しいメッセージを書き込むことができるクラスです。
以下のコードスニペットは、Thunderbird のメールストレージにメッセージを書き込む方法を示しています。
- FileStream で Thunderbird のストレージファイルを開きます。
- インスタンスを作成します MboxrdStorageWriter クラスを使い、上記ストリームをコンストラクタに渡します。
- 上記を使用して新しいメッセージを作成します MailMessage クラス。
- 呼び出す WriteMessage() メソッドに渡し、上記を使用します MailMessage インスタンスを使用してメッセージを Thunderbird のストレージに追加します。
- すべてのストリームを閉じます。
// 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();