Save attachments

To get and save attachments, follow these steps:

  1. Instantiate the Viewer object. Specify a file that contains attachments.
  2. Call the get_attachments method. It returns the attachment collection.
  3. Iterate through the collection. To save an attachment, call the save_attachment method.

The following code snippet shows how to get and save all attachments from the MSG file:

Note
NOTE: provided code snippet suits all format families that support attachments: emails, Outlook data files, archives, and PDF documents.
with gv.Viewer("with_attachments.msg") as viewer:
        attachments = viewer.get_attachments()

        print("\nAttachments:")
        for attachment in attachments:
            print(attachment)

    print(f"\nAttachments retrieved successfully.")