어떻게 시작할 수 있는 Aspose.Email FOSS for Python
aspose-email-foss Python은 MIT 라이센스를 받은 무료 도서관으로, 창조, 읽기 및 Outlook MSG 파일 및 CFB 컨테이너를 변환 — Microsoft Office 요구 사항, 원주민 필요 없음 확장, Python에서 순수한 PyPI.
단계별 가이드
단계 1 : 패키지를 설치합니다.
PIP를 사용하여 PyPI에서 설치하십시오 :
pip install aspose-email-foss설치가 제대로 충전된지 확인하십시오 :
from aspose.email_foss.msg import MapiMessage
print("aspose-email-foss is ready.")단계 2 : 수입 필요한 클래스
메시지 만들기, 속성 할당 및 형식 변환에 필요한 모듈을 가져오십시오 :
from datetime import datetime, timezone
from aspose.email_foss import msg
from aspose.email_foss.msg import MapiMessage, PropertyId단계 3: MSG 파일 만들기
사용하기 MapiMessage.create() 주제와 몸과 메시지를 만들기 위해.Sender metadata 설정 와 함께 PropertyId 지속, 수신자를 추가하고 파일을 첨부합니다.
message = MapiMessage.create("Getting Started", "Hello from aspose-email-foss!")
message.set_property(PropertyId.SENDER_NAME, "Build Agent")
message.set_property(PropertyId.SENDER_EMAIL_ADDRESS, "agent@example.com")
message.set_property(
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("notes.txt", b"Meeting notes go here.\n", mime_type="text/plain")
message.save("getting-started.msg")
print("getting-started.msg written.")단계 4 : MSG 파일을 다시 읽으십시오.
저장된 파일을 사용하여 다운로드합니다. MapiMessage.from_file() 컨텍스트 관리자로서의 접근 subject 그리고 body 반환된 물건에서 직접 소유한 재산.
with MapiMessage.from_file("getting-started.msg") as message:
print(f"Subject: {message.subject}")
print(f"Body : {message.body}")5단계: MSG를 EML로 변환합니다.
to_email_bytes() 로드된 메시지를 RFC 5322 형식으로 변환합니다. A 는 .eml 기본 도서관을 가진 파일.
from pathlib import Path
with MapiMessage.from_file("getting-started.msg") as message:
Path("getting-started.eml").write_bytes(message.to_email_bytes())
print("getting-started.eml written.")일반적인 문제와 해결책
ModuleNotFoundError: No module named 'aspose' 패키지는 활성 Python 환경에 설치되지 않습니다. pip install aspose-email-foss 동일한 가상 환경에서 당신은 스크립트를 실행하는 데 사용됩니다. pip show aspose-email-foss.
FileNotFoundError 전화할 때 MapiMessage.from_file() 당신이 통과 한 경로는 존재하지 않거나 OS에 대한 잘못된 분리기를 사용합니다. pathlib.Path 휴대용 도로를 구축하기 위해 : MapiMessage.from_file(Path("folder") / "file.msg").
MSG 파일은 Outlook에서 열리지만 주제가 표시되지 않습니다. MapiMessage.create() 첫 번째 주제는 입장 논쟁으로 받아들여야 한다. 빈 줄에서 Outlook은 메시지를 비명으로 표시합니다.이 문자를 통과하지 않은 줄을 입력하거나 설정하십시오. 명시적으로 와 set_property(PropertyId.SUBJECT, "My Subject").
EML 변환은 빈 몸을 생성합니다. to_email_bytes() 사용하기 body_html 만일 그가 앉아서 다시 떨어지면 body.확인하십시오, 그에 대 한 적어도 이러한 속성 중 하나는 MSG를 충전한 후에 비공개입니다. from_file().
수신자 또는 주제에 있는 유니코드 콘텐츠가 흔들리고 있습니다. 패스 unicode_strings=True 를 위해서 MapiMessage.create() 링크 속성을 보장하기 위해서는 유니코드 (PT_UNICODE) 대신 ANSI ( PT_STRING8)에 저장됩니다.
자주 묻는 질문들
aspose-email-foss는 Microsoft Office가 필요합니까?
도서관은 완전히 자체 콘텐츠입니다. 그것은 읽고 작성 바이너리 MSG 및 CFB 형식은 Python에서 원래, Microsoft Office, COM 자동화 또는 Win32 API에 의존하지 않습니다.
이 도서관을 Linux 또는 macOS에서 사용할 수 있습니까?
예요 ᄒᄒ. aspose-email-foss Python은 순수하고 Python 3.10을 지원하는 모든 플랫폼에서 실행됩니다. 또는 이후 - Windows, macOS, Linux, Docker 컨테이너 및 서버없는 기능을 포함합니다.
도서관은 상업용으로 무료로 이용할 수 있나요?
예. MIT 라이센스에 따라 발행됩니다.당신은 사용, 수정 및 재배포 할 수 있습니다 어떤 목적을 위해, 상업용 응용 프로그램을 포함하여, 로얄티 또는 부여 요구 사항 이외의 라이선스 텍스트.
CC 및 BCC 수신자를 어떻게 추가합니까?
패스 recipient_type=msg.RECIPIENT_TYPE_CC 또는 msg.RECIPIENT_TYPE_BCC 세 번째로 논쟁은 add_recipient():
message.add_recipient("bob@example.com", display_name="Bob", recipient_type=msg.RECIPIENT_TYPE_CC)어떻게 하나의 MSG를 다른 하나 안에 삽입합니까?
사용하기 MapiMessage.add_embedded_message_attachment(),내부를 통과하는 것 MapiMessage 첫 번째 주장으로서의 논쟁:
inner = MapiMessage.create("Inner message", "Embedded body.")
outer = MapiMessage.create("Outer message", "See attachment.")
outer.add_embedded_message_attachment(inner, "inner.msg")
outer.save("outer.msg")