Posted on:April 18, 2019 at 07:00 AM

How to Backup Gmail Emails to EML Files

How to Backup Gmail Emails to EML Files

Google Storage Space Issue

Google Storage Space Warning

Google provides 15GB of free storage per account. Recently, I received a notification that one of my accounts was almost full. After checking where the space was being used, I found that while Photos and Drive were using minimal space, Gmail was the main consumer.

Gmail Backup Options

Google’s Built-in Backup

Google Account allows you to backup emails in MBOX format, but the file size is too large for my needs.

Alternative Solution

Previously, when leaving Bardel, I found a script for backing up Gmail. Here’s how it looked:

Gmail Backup Interface

While the original tool is no longer supported, the source code is still available. I forked it to my GitHub repository and made some modifications to make it work:

Gmail Backup Com

Docker-based Solution

Since Python 2 is no longer supported and setting up the development environment is difficult, I containerized the solution using Docker.

Usage

# Build the Docker container
docker-compose build

# Run with debugger
docker-compose run app python -m pdb gmail-backup.py

# Run backup
docker-compose run app python gmail-backup.py [backup dir] [gmail id] [gmail password] [start date] [end date]

This will create individual EML files for each email, organized in date-based directories within your specified backup directory.