מבוא

Aspose.Email FOSS for Python is now available on PyPI: a free, MIT-licensed library for creating, reading, and converting Outlook .msg קבצים באופן מלא ב-Python, ללא תלות ב-Microsoft Office או בכל הרחבה מקומית. התקן אותו באמצעות pip install aspose-email-foss>=26.3 והתחל לעבוד עם מכולות MSG ו-CFB מיידית.

הספרייה ממוקדת ב‑Python 3.10 ומעלה. היא מממשת את פורמט הקובץ הבינארי המשולב (CFB) ואת פורמט הודעות MSG מאפס, ומספקת שליטה דטרמיניסטית על אופן סריאליזציית והקריאת הודעות דוא״ל. מכיוון שהמימוש הוא Python טהור, הוא פועל באופן זהה ב‑Windows, macOS, Linux ובסביבות מכולות.

Aspose.Email FOSS is designed for developers building email processing pipelines, compliance archival tools, forensic analysis workflows, or any application that needs to create or inspect Outlook-compatible message files without a running Exchange or Outlook installation.


תכונות מרכזיות

יצירת קבצי MSG

בנה קבצים תואמי Outlook .msg קבצים מאפס באמצעות MapiMessage.create(). הגדר תכונות MAPI סטנדרטיות כגון נושא, שולח, זמן מסירה, ושדות תצוגה דרך ה- PropertyId enum. הוסף נמענים באמצעות add_recipient() וּקבצי מצורפים באמצעות add_attachment(), ואז שמור את התוצאה על הדיסק.

from aspose.email_foss import msg

message = msg.MapiMessage.create(
    "Quarterly status update and rollout plan",
    "Hello team,\n\nPlease find the latest rollout summary attached.\n\nRegards,\nEngineering",
)

message.set_property(msg.PropertyId.SENDER_NAME, "Build Agent")
message.set_property(msg.PropertyId.SENDER_EMAIL_ADDRESS, "build.agent@example.com")
message.set_property(msg.PropertyId.INTERNET_MESSAGE_ID, "<example-001@example.com>")

message.add_recipient("alice@example.com", display_name="Alice Example")
message.add_recipient("bob@example.com", display_name="Bob Example")
message.add_recipient(
    "carol@example.com",
    display_name="Carol Example",
    recipient_type=msg.RECIPIENT_TYPE_CC,
)

message.add_attachment("hello.txt", b"sample attachment\n", mime_type="text/plain")
message.save("example-message.msg")

קריאה והמרה מ‑MSG ל‑EML

טען קיים .msg קובץ עם MapiMessage.from_file() ולהפוך אותו ל-Python סטנדרטי EmailMessage אובייקט דרך to_email_message(). משם, סדר ל-EML בתים לאחסון או העברה דרך SMTP.

from aspose.email_foss import msg

with msg.MapiMessage.from_file("example-message.msg") as loaded:
    email_message = loaded.to_email_message()
    eml_bytes = email_message.as_bytes()

with open("example-message.eml", "wb") as f:
    f.write(eml_bytes)

בדיקת פנימיות MSG

השתמש MsgReader וההתשתית שלו CFBReader לבדוק את המבנה הבינארי של קובץ MSG. לגשת למטא‑דאטה של CFB (גרסה, גודל סקטור, מספר ערכי ספרייה) ולחזור על רשומות המאפיינים של MAPI ברמת הבינארי.

from aspose.email_foss import msg

reader = msg.MsgReader.from_file("example-message.msg")
cfb = reader.cfb_reader

print(f"CFB major_version={cfb.major_version}")
print(f"sector_size={cfb.sector_size}")
print(f"directory_entries={cfb.directory_entry_count}")

for entry in reader.iter_top_level_fixed_length_properties():
    tag = entry.property_tag
    print(f"tag=0x{tag:08X} flags=0x{entry.flags:08X} value={entry.value.hex()}")

reader.close()

גישה ברמת‑הנמוכה ל‑CFB

קרא ועבור על כל מכולת Compound File Binary באמצעות CFBReader. מונה אחסונים וזרמים, פותר נתיבים לפי שם, ומחלץ נתוני זרם גולמיים לעיבוד מותאם אישית.

from aspose.email_foss.cfb import CFBReader

reader = CFBReader.from_file("example-message.msg")

for entry in reader.iter_storages():
    print(f"Storage: {entry.name}")

for entry in reader.iter_streams():
    data = reader.get_stream_data(entry.stream_id)
    print(f"Stream: {entry.name} size={len(data)}")

reader.close()

התחלה מהירה

התקינו את הספרייה וצור את קובץ ה‑MSG הראשון שלכם בפחות מעשר שורות:

pip install aspose-email-foss>=26.3
from aspose.email_foss import msg

message = msg.MapiMessage.create("Hello from Python", "This is a test message.")
message.set_property(msg.PropertyId.SENDER_EMAIL_ADDRESS, "sender@example.com")
message.add_recipient("recipient@example.com", display_name="Recipient")
message.save("hello.msg")

with msg.MapiMessage.from_file("hello.msg") as loaded:
    eml = loaded.to_email_message()
    print(eml["Subject"])

פורמטים נתמכים

פורמטייבואייצוא
MSGכןכן
CFBכןכן

קוד פתוח & רישוי

Aspose.Email FOSS for Python is released under the MIT License. אתה יכול להשתמש בו בפרויקטים אישיים, פנימיים ומסחריים ללא הגבלה. קוד המקור זמין ב GitHub.


התחלה