Skip to content

Attachment

Provides access to the properties of an attachment in an Outlook MSG file.

These properies include the attached file's original file-name, its last-modified date, size, and content-type (MIME-type).

>>> from oxmsg import Message

>>> msg = Message.load("message.msg")
>>> msg.attachment_count
1
>>> attachment = msg.attachments[0]
>>> attachment.file_name
'financial-forecast.xlsx'
>>> with open(attachment.file_name, "wb") as f:
...     f.write()

Attachment

A file attached to an Outlook email message.

attached_by_value() -> bool

True when the PidTagAttachDataBinary property contains the attachment data.

This is as opposed to "by-reference" where only a path or URL is stored.

file_bytes() -> bytes | None

The attachment binary, suitable for saving to a file when detaching.

file_name() -> str | None

The full name of this file as it was originally attached.

Like "FY24-quarterly-projections.xlsx". Does not include a path.

last_modified() -> dt.datetime | None

Timezone-aware UTC datetime when this attachment was last modified.

None if this property is not present on the attachment.

mime_type() -> str | None

ISO 8601 str representation of time this attachment was last modified.

properties() -> Properties

Provides access to the properties of this OXMSG object.

size() -> int

Length in bytes of this attachment.