| layout | default |
|---|---|
| title | IMAP Backup & Restore Tool - Open Source Email Backup Solution |
| description | Free open-source Python tool for backing up and restoring IMAP email accounts. Features S3 cloud storage, GPG encryption, Docker support, and zero dependencies. Secure your emails today. |
| keywords | imap backup tool, email backup software, python imap backup, s3 email backup, gpg email encryption, docker email backup, open source backup, mailbox backup, email migration tool, imap restore |
| author | chris2k20 |
| image | /imapbackup/assets/images/og-image.png |
The complete open-source solution for backing up, restoring, and migrating IMAP email accounts.
- 📧 Full IMAP Backup - Download all emails from any IMAP server to standard mbox format
- 🔄 Smart Restore - Upload mbox files back to IMAP servers with duplicate detection
- ☁️ S3 Integration - Store backups in S3-compatible storage (AWS S3, MinIO, Hetzner, Wasabi)
- 🔐 GPG Encryption - Encrypt backups with GPG for secure storage
- 📦 Zero Dependencies - Pure Python implementation, no external libraries required
- 🐳 Docker Ready - Pre-built Docker image for easy deployment
- ⚡ Incremental Backups - Only download new messages on subsequent runs
- 🔧 Flexible Key Import - Import GPG keys from files, URLs, or environment variables
- ✅ Email server migrations
- ✅ Automated daily backups
- ✅ Disaster recovery planning
- ✅ Compliance and archival
- ✅ Cloud storage integration
- ✅ Kubernetes deployments
- ✅ Personal email backup
# Basic backup
docker run --rm -v $(pwd)/backups:/data \
user2k20/imapbackup \
-s imap.example.com -u user@example.com -e
# Backup with S3 upload and GPG encryption
docker run --rm -v $(pwd)/backups:/data \
user2k20/imapbackup \
-s imap.example.com -u user@example.com -e \
--s3-upload \
--s3-endpoint=https://s3.hetzner.cloud \
--s3-bucket=email-backups \
--s3-access-key=$S3_KEY \
--s3-secret-key=$S3_SECRET \
--gpg-encrypt \
--gpg-recipient=backup@example.com \
--gpg-import-key=https://example.com/keys/public.asc# Clone repository
git clone https://github.com/chris2k20/imapbackup.git
cd imapbackup
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run backup
python3 imapbackup.py -s imap.example.com -u user@example.com -e- Docker Setup Guide - Quick start with Docker
- Python/venv Setup Guide - Installation with Python virtual environments
- Backup Guide - Complete backup strategies and examples
- Restore Guide - How to restore emails from backups
- S3 Configuration - Configure AWS S3, MinIO, Hetzner, and other providers
- GPG Encryption Guide - Set up encryption for secure backups
- GPG Key Import Guide - Flexible key import from files, URLs, environment variables
# Cron job for daily backups at 2 AM
0 2 * * * docker run --rm -v /backups:/data user2k20/imapbackup \
-s imap.example.com -u user@example.com -p @/root/.password -e \
--s3-upload --s3-endpoint=https://s3.hetzner.cloud \
--s3-bucket=backups --s3-access-key=$KEY --s3-secret-key=$SECRET# Backup from old server
python3 imapbackup.py -s old.server.com -u user@old.com -e
# Restore to new server
python3 imapbackup.py -r -s new.server.com -u user@new.com -eapiVersion: batch/v1
kind: CronJob
metadata:
name: email-backup
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: backup
image: user2k20/imapbackup:latest
args:
- -s
- imap.example.com
- -u
- user@example.com
- -e
- --s3-upload
- --gpg-encrypt# Backup with encryption - no GPG keyring mount needed!
docker run --rm -v $(pwd)/backups:/data \
user2k20/imapbackup \
-s imap.gmail.com -u myemail@gmail.com -e \
--s3-upload --s3-bucket=secure-backups \
--gpg-encrypt --gpg-recipient=backup@example.com \
--gpg-import-key=env:GPG_PUBLIC_KEY- MIT Licensed - Use it anywhere, modify it freely
- No Vendor Lock-in - Standard mbox format works with any email client
- Community Driven - Actively maintained since 2007
- Zero Dependencies - Pure Python, runs anywhere Python 3.6+ is available
- Battle Tested - Used by thousands of users worldwide
- Docker Official - Pre-built images on Docker Hub
- Kubernetes Ready - Perfect for cloud-native deployments
- Read-Only IMAP Operations - Never modifies source emails during backup
- GPG Encryption - Industry-standard OpenPGP encryption
- S3 Compatible - Works with all major cloud providers
- Flexible Key Management - Import keys from files, URLs, or environment variables
- Clean Code - Well-documented Python codebase
- Comprehensive Docs - Detailed guides for every use case
- Easy Integration - Simple CLI interface, scriptable
- Active Support - GitHub issues and pull requests welcome
Email Backup Solutions: Perfect for Gmail backup, Office 365 backup, Exchange backup, Outlook backup, and any IMAP-compatible email service.
Server Migration: Seamlessly migrate emails between providers - move from Gmail to ProtonMail, Office 365 to Google Workspace, or any IMAP server to another.
Compliance & Archival: Meet GDPR, HIPAA, and other regulatory requirements with encrypted email archives stored securely in S3-compatible storage.
Disaster Recovery: Automated daily backups ensure you never lose important emails. Restore to any IMAP server in minutes.
Self-Hosted Email: Perfect companion for self-hosted mail servers using Dovecot, Postfix, Zimbra, or any IMAP-compatible server.
-s HOST- IMAP server hostname-u USER- Username/email address-p PASS- Password or@/path/to/fileto read from file-e- Use SSL/TLS (recommended)-d DIR- Directory for mbox files
-a- Append mode (default, incremental backups)-y- Overwrite mode (full backup)-r- Restore mode (upload to IMAP server)
-f FOLDERS- Backup specific folders (comma-separated)--exclude-folders=FOLDERS- Exclude specific folders
--s3-upload- Enable S3 integration--s3-endpoint=URL- S3 endpoint URL--s3-bucket=BUCKET- S3 bucket name--s3-access-key=KEY- S3 access key--s3-secret-key=KEY- S3 secret key--s3-prefix=PREFIX- Optional S3 path prefix
--gpg-encrypt- Enable GPG encryption/decryption--gpg-recipient=EMAIL- GPG key ID or email address--gpg-import-key=SOURCE- Import public key from:- File:
/path/to/key.asc - URL:
https://example.com/key.asc - Environment:
env:GPG_PUBLIC_KEY
- File:
- Gmail / Google Workspace
- Microsoft 365 / Outlook.com
- ProtonMail
- Fastmail
- Zoho Mail
- Apple iCloud Mail
- Yahoo Mail
- Self-hosted (Dovecot, Postfix, Zimbra, etc.)
- Any IMAP-compatible server
- AWS S3 - Amazon Web Services
- Hetzner Storage Box - European data centers
- MinIO - Self-hosted object storage
- Wasabi - Hot cloud storage
- Backblaze B2 - Affordable cloud storage
- DigitalOcean Spaces - Simple object storage
- Cloudflare R2 - Zero egress fees
- Docker - Pre-built image:
user2k20/imapbackup - Docker Compose - Easy multi-container setups
- Kubernetes - CronJob examples included
- Python venv - Isolated Python environment
- Bare Metal - Direct Python execution
- Cron - Traditional Unix scheduling
- Docker installed
- That's it! Everything else is included in the image
- Python 3.6 or higher (tested with 3.8+)
- GPG (for encryption):
apt install gnupg - Python dependencies:
pip install -r requirements.txt
- GitHub Repository - Source code and issues
- Docker Hub - Pre-built Docker images
- Documentation - Complete guides and examples
- License - MIT License
imap backup, email backup tool, python imap, backup imap emails, gmail backup, office 365 backup, email migration, imap restore, mailbox backup, mbox backup, docker email backup, s3 email backup, encrypted email backup, gpg email encryption, automated email backup, email archival, email disaster recovery, open source email backup, imap sync, email server migration, dovecot backup, postfix backup, kubernetes email backup, cloud email backup, secure email backup
Contributions are welcome! Please feel free to submit issues, fork the repository, and create pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
Originally developed around 2007 and actively maintained ever since. Thanks to all contributors who have helped make this tool better over the years.
⭐ Star this repository if you find it useful!
🐛 Found a bug? Open an issue
💬 Have questions? Check the documentation