James Ridgway - Software Engineer

Attachment Downloader

Attachment Downloader is a simple tool for downloading email attachments for all emails in a given folder using an IMAP client.


Attachment Downloader requires Python 3+.

$ pip install attachment-downloader


Usage: attachment-downloader [options]

  -h, --help            show this help message and exit
  --host=HOST           IMAP Host
  --username=USERNAME   IMAP Username
  --password=PASSWORD   IMAP Password
                        IMAP Folder to extract attachments from
                        Attachment filename (jinja2) template.
                        Output directory for attachment download


$ attachment-downloader --host imap.example.com --username mail@example.com --password pa55word --imap-folder invoices --output ~/Downloads

Filename Template

By default attachments will be downloaded using their original filename to the folder specified by -output.

You can customise the download filename using a jinja2 template for the argument --filename-template.

The following variables are supported: * message_id * attachment_name * subject * local_date

In the following example, downloads will be placed within the output folder grouped into a folder hierarchy of date, message ID, subject:

--filename-template="{{local_date}}/{{ message_id }}/{{ subject }}/{{ attachment_name }}"