Quickstart

빠른 시작: MSG 파일 만들기 및 읽기

이 가이드는 aspose.email_foss에서 제공하는 MapiMessage를 사용하여 새 설치에서 작동하는 MSG 파일까지 몇 단계만에 안내합니다.


필수 조건

요구 사항세부 사항
Python3.10 이상
pip현재 버전
OSWindows, macOS, 또는 Linux
Dependencies없음 — pure 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()로 저장된 파일을 로드하고 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.")

다음 단계

참조

 한국어