Attachment class

Attachment class

Represents an attachment file contained by an email message, archive, PDF document, or Outlook data file.

The Attachment type exposes the following members:

Constructors

Constructor Description
init Initializes a new Attachment instance.
init Initializes a new Attachment instance.
init Initializes a new instance of the Attachment class.
init Initializes a new instance of the Attachment class.

Methods

Method Description
to_string Returns a string that represents the current object.

Properties

Property Description
file_name The attachment file name.
file_path The attachment relative path, e.g. folder/file.docx, or the filename when the file is located in the root of an archive, in an e‑mail message, or a data file.
file_type The attachment file type.
id The unique identifier of the attachment in the context of a single file that contains this attachment.
size The attachment file size in bytes.

Example

from groupdocs.viewer import Viewer

with Viewer("with_attachments.msg") as viewer:
    for attachment in viewer.get_attachments():
        # Access attachment properties, e.g., file name
        print(attachment.file_name)
        # Save the attachment to a file path
        viewer.save_attachment(attachment, f"./out/{attachment.file_name}")

See Also