QuickStart

Quickstart: יצירת וקריאת קובץ MSG

מדריך זה לוקח אותך מ-התקנה חדשה לקובץ MSG עובד בכמה שלבים באמצעות MapiMessage מתוך aspose.email_foss.


דרישות

דרישותפרטים
Python3.10 or later
פיפגרסה נוכחית
OSWindows, MacOS או Linux
תלויותלא – Python טהור

שלב 1 - התקנת החבילה

pip install aspose-email-foss

אישור ההתקנה:

from aspose.email_foss.msg import MapiMessage
print("aspose-email-foss is ready.")

שלב 2 – יצירת קובץ MSG

שימוש MapiMessage.create() כדי לבנות הודעה, הגדרת תכונות של שליחת עם PropertyId, הוסף קבלן, הוסיף קובץ וקרא save() כדי לכתוב את .msg יצוא.

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.")

שלב 3 – קרא את קובץ MSG בחזרה

להעלות את הקובץ שנשמר עם MapiMessage.from_file() גישה ל- The subject ו body נכסים ישירות.

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}")

שלב 4 – הפוך ל- EML

to_email_message() החזרה של Python סטנדרטי email.message.EmailMessage שימוש - Use to_email_bytes() כדי לכתוב מוכן לשדר RFC 5322 .eml קובץ .

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.")

שלבים הבאים

ראה גם

 עברית