소개
Aspose.Email FOSS for Python이 이제 PyPI에서 제공됩니다: Outlook .msg 파일을 완전히 Python에서 생성, 읽기 및 변환할 수 있는 무료 MIT 라이선스 라이브러리이며, Microsoft Office나 네이티브 확장에 의존하지 않습니다. pip install aspose-email-foss>=26.3으로 설치하고 즉시 MSG 및 CFB 컨테이너 작업을 시작하세요.
이 라이브러리는 Python 3.10 이상을 대상으로 합니다. Compound File Binary (CFB) 형식과 MSG 메시지 형식을 처음부터 구현하여 이메일 메시지가 직렬화되고 읽히는 방식을 결정론적으로 제어할 수 있습니다. 구현이 순수 Python으로 이루어졌기 때문에 Windows, macOS, Linux 및 컨테이너화된 환경에서 동일하게 실행됩니다.
Aspose.Email FOSS는 이메일 처리 파이프라인, 규정 준수 보관 도구, 포렌식 분석 워크플로우를 구축하거나 실행 중인 Exchange 또는 Outlook 설치 없이 Outlook 호환 메시지 파일을 생성하거나 검사해야 하는 모든 애플리케이션을 위한 개발자를 위해 설계되었습니다.
주요 기능
MSG 파일 만들기
MapiMessage.create()를 사용하여 처음부터 Outlook 호환 .msg 파일을 빌드합니다. PropertyId 열거형을 통해 제목, 발신자, 배달 시간 및 표시 필드와 같은 표준 MAPI 속성을 설정합니다. 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() 로 로드하고 to_email_message()을 통해 표준 Python EmailMessage 객체로 변환합니다. 그런 다음, 저장 또는 SMTP를 통한 전달을 위해 EML 바이트로 직렬화합니다.
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 액세스
CFBReader를 사용하여 모든 Compound File Binary 컨테이너를 읽고 탐색합니다. 스토리지와 스트림을 열거하고, 이름으로 경로를 해결하며, 사용자 지정 처리를 위해 원시 스트림 데이터를 추출합니다.
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()
빠른 시작
라이브러리를 설치하고 10줄 이하로 첫 번째 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은 MIT License 하에 릴리스되었습니다. 개인, 내부 및 상업 프로젝트에서 제한 없이 사용할 수 있습니다. 소스 코드는 GitHub에서 확인할 수 있습니다.