Quickstart
Quickstart: Create and Read an MSG File
This guide takes you from a fresh install to a working MSG file in a few steps using
MapiMessage from aspose.email_foss.
Prerequisites
| Requirement | Detail |
|---|---|
| Python | 3.10 or later |
| pip | current version |
| OS | Windows, macOS, or Linux |
| Dependencies | None — pure Python |
Step 1 — Install the Package
pip install aspose-email-fossConfirm the install:
from aspose.email_foss.msg import MapiMessage
print("aspose-email-foss is ready.")Step 2 — Create an MSG File
Use MapiMessage.create() to build a message, set sender properties with PropertyId,
add a recipient, attach a file, and call save() to write the .msg output.
from datetime import datetime, timezone
from aspose.email_foss import msg
message = msg.MapiMessage.create("Hello from Python", "This is the message body.")
message.set_property(msg.PropertyId.SENDER_NAME, "Build Agent")
message.set_property(msg.PropertyId.SENDER_EMAIL_ADDRESS, "agent@example.com")
message.set_property(
msg.PropertyId.MESSAGE_DELIVERY_TIME,
datetime(2026, 1, 1, 9, 0, tzinfo=timezone.utc),
)
message.add_recipient("alice@example.com", display_name="Alice Example")
message.add_attachment("readme.txt", b"Hello, world!\n", mime_type="text/plain")
message.save("quickstart.msg")
print("quickstart.msg written.")Step 3 — Read the MSG File Back
Load the saved file with MapiMessage.from_file() and access the subject and body
properties directly.
from aspose.email_foss import msg
with msg.MapiMessage.from_file("quickstart.msg") as message:
print(f"Subject : {message.subject}")
print(f"Body : {message.body}")Step 4 — Convert to EML
to_email_message() returns a standard Python email.message.EmailMessage object. Use
to_email_bytes() to write a ready-to-send RFC 5322 .eml file.
from pathlib import Path
from aspose.email_foss import msg
with msg.MapiMessage.from_file("quickstart.msg") as message:
Path("quickstart.eml").write_bytes(message.to_email_bytes())
print("quickstart.eml written.")Next Steps
- Installation Guide: Virtual-environment setup, pip options, and verification
- Getting Started Overview: Prerequisites summary and capability overview
- Features and Functionalities: Deep-dive into every feature
- API Reference