// guides

Automatically save email attachments to a folder (Gmail, Outlook, any IMAP)

Download invoices, PDFs and images from your inbox into folders automatically, filtered by sender and file type. Free script that never deletes email, plus an n8n version.

Updated 2026-10-16 · about 10 minutes

Rather not set it up yourself? Describe your task in one sentence and we'll build and test it for you, free →

Steps

  1. Create an app password

    Gmail and Outlook require 2-step verification plus an app password for IMAP. Your normal password won't work.

  2. Download the agent

    Get the attachment saver agent and try it on the bundled sample emails: python3 attachment_saver.py --eml-dir sample_emails --dry-run.

  3. Pick what to save

    EXTENSIONS=pdf,xlsx,csv and FROM_CONTAINS=invoice,billing@ keep only what matters. DAYS=7 sets how far back to look.

  4. Choose the folder

    Set SAVE_DIR to a Dropbox, OneDrive or Google Drive synced folder and your attachments end up in the cloud too.

  5. Run hourly

    0 * * * * in cron. Files that were already saved are skipped.

Safe by design

The script only reads mail. It never deletes, moves or marks emails as read. Your password stays in a local .env file on your own machine.

Skip the setup: free download

The Attachment saver agent does all of this. It's tested, MIT-licensed, and comes as an n8n workflow plus a Python script.

Get the free Attachment saver agent → Or have us build yours →

FAQ

Does it work with Outlook / Microsoft 365?

Yes, if IMAP is enabled for your account: IMAP_HOST=outlook.office365.com.

Can I save to Google Drive directly?

In n8n Cloud, replace the write-to-disk node with the Google Drive upload node.

Related guides

New guides

Want one built for your task?

Describe it in one sentence. We build it, test it and email it to you, usually within 24h. Free while we're in beta.

We'll only email you about your agent and TaskToAgent.