Quickstart

Quickstart: Bir MSG dosyası oluşturun ve okuyun

Bu rehber sizi yeni bir yükleme ile çalışan MSG dosyasına birkaç adımda kullanarak götürür. MapiMessage -den aspose.email_foss.


Prerequisites

RequirementDetail
Python3.10 or later
Pip içinMevcut versiyonu
OSWindows, MacOS veya Linux
DependenciesHiçbir şey yok - saf Python

Adım 1 - Paket yükleme

pip install aspose-email-foss

Install için tıklayınız:

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

Adım 2 - Bir MSG Dosyası Oluşturmak

Kullanım MapiMessage.create() Bir mesaj oluşturmak için, göndericiler özelliklerini ayarlayın PropertyId, bir alıcı ekleyin, bir dosya ekleyin ve arama yapın. save() yazmak için The .msg çıkış için.

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

Adım 3 - MSG Dosyası Geri Okunma

kaydedilen dosyayı ile yükleme MapiMessage.from_file() ve erişim için subject ve body Doğrudan mülkler.

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

Adım 4 - EML’ye Dönüştürme

to_email_message() standart Python’u geri getiriyor email.message.EmailMessage Kullanım - Object to_email_bytes() RFC 5322 için hazır bir yazı yazmak için .eml Dosya için.

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

Sonraki adımlar

See Also

 Türkçe