Quickstart

Quickstart: إنشاء قراءة ملف MSG

هذا الدليل يأخذك من التثبيت الجديد إلى ملف MSG يعمل في خطوات قليلة باستخدام MapiMessage من aspose.email_foss.


المعايير

مطلوبالتفاصيل
Python3.10 or later
PIPالنسخة الحالية
OSويندوز أو ماكوس أو لينكس
الاعتمادلا شيء - 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() من أجل كتابة The .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 Back

تحميل الملف المحفوظ مع MapiMessage.from_file() و الوصول إلى 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 الموضوع : استخدام 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.")

الخطوات التالية

 العربية