将消息写入 Thunderbird MBOX 文件

Contents
[ ]

如果您需要以编程方式向 Thunderbird 邮件存储文件添加新消息,Aspose.Email 提供了 MboxrdStorageWriter 类来简化此任务。此类允许您将消息写入现有的 MBOX 文件。

以下步骤概述了如何使用 MboxrdStorageWriter 以及 MailMessage 用于在 Thunderbird 邮件格式中创建和存储消息的类。同时提供了代码示例以演示该过程。

  1. 创建该类的实例 MboxrdStorageWriter 类,传入 Thunderbird 存储文件的路径和一个 MboxSaveOptions 对象传递给其构造函数。
  2. 使用以下方式准备新消息 MailMessage 类。
  3. 调用 write_message() 方法并传递 MailMessage 实例将消息添加到 Thunderbird 存储。
  4. 将写入器用作上下文管理器 ( with 语句),以便写入完成后关闭文件。
import aspose.email as ae
from aspose.email.storage.mbox import MboxrdStorageWriter, MboxSaveOptions

with MboxrdStorageWriter(data_dir + "ExampleMBox_out.mbox", MboxSaveOptions()) as writer:
    # Prepare a new message using the MailMessage class
    message = ae.MailMessage("from@domain.com", "to@domain.com",
                             "EML generated for MBOX",
                             "Added with Aspose.Email for Python via .NET")
    message.is_draft = False

    # Add the message to the storage
    writer.write_message(message)