Dump all Email from GMail via API (no IMAP). Very useful if your GMail administrator disabled IMAP for "security" reasons.
- Clone this code, I tested it with Python 3
- Go to Google API Developer Console and create a set of client credentials enabled for the GMail API
- Download the credentials JSON and save as
client_secrets.json
- Install Virtualenv
- Create virtualenv with
virtualenv -p python3 venv
- Activate virtualenv with
source venv/bin/activate
- Install Google API Client Libraries with
pip install google-api-python-client
- Run code with python gmail-dump.py.
On first run your browser should open up and ask for your Google Authorization. It will then download all Email into the maildir folder mail.
You can use mutt like mutt -f mail
to browse through the downloaded email.
On successive runs the script will only download new messages. Ideal for running as a nightly cron job.
- I use the message ID as file name for the mail files, it seems to work so far. Please report if you have a problem with that.
- This script just dumps the bare email and completely ignores any labels. Pull requests are welcome.