Convert MBOX to PST
Convert MBOX to PST. Basic Conversion
When migrating mail data from clients like Mozilla Thunderbird to Microsoft Outlook, converting MBOX archives to the PST (Personal Storage Table) format is often required. The PST format is native to Outlook and Exchange and supports advanced features such as folder structures and MAPI-based message handling.
Aspose.Email allows you to transfer messages from MBOX files into Outlook-compatible storage with full control over the conversion process. The example below loads the messages from an MBOX archive and saves them into a structured Outlook data file:
- Initialize the MBOX reader with MboxStorageReader.create_reader().
- Create a PST file with PersonalStorage.create().
- Add a mail folder — “Inbox”, for example — to the storage.
- Loop through the messages, convert each of them to a MapiMessage and insert it into the folder.
from aspose.email.mapi import MapiMessage
from aspose.email.storage.mbox import MboxStorageReader, MboxLoadOptions
from aspose.email.storage.pst import PersonalStorage, FileFormatVersion, StandardIpmFolder
# Load the source file
mbox = MboxStorageReader.create_reader("source.mbox", MboxLoadOptions())
# Create the destination Outlook data file
with PersonalStorage.create("converted.pst", FileFormatVersion.UNICODE) as personal_storage:
# Add a folder to hold the imported messages
folder_info = personal_storage.create_predefined_folder("Inbox", StandardIpmFolder.INBOX)
# Process each message from the source file
for eml in mbox.enumerate_messages():
msg = MapiMessage.from_mail_message(eml)
folder_info.add_message(msg)
Convert MBOX to PST while Preserving or Removing a Signature
When converting MBOX files to PST format, you may want to exclude digital signatures from the messages for cleaner output or compatibility purposes. Aspose.Email provides a convenient option to remove these signatures during the conversion process by using the remove_signature property of the MboxToPstConversionOptions class.
The example below demonstrates how to enable this option in your Python project:
import aspose.email as ae
personalStorage = ae.storage.pst.PersonalStorage.create("target.pst", ae.storage.pst.FileFormatVersion.UNICODE)
conversion_options = ae.storage.MboxToPstConversionOptions()
conversion_options.remove_signature = True
ae.storage.MailStorageConverter.mbox_to_pst( ae.storage.mbox.MboxrdStorageReader("source.mbox", ae.storage.mbox.MboxLoadOptions()), personalStorage, "Inbox", conversion_options)