A production-ready containerized service that synchronizes emails between IMAP servers using imapsync. Built on Alpine Linux with comprehensive logging, health checks, and deployment options for Docker Compose and Portainer.
- Multiple sync modes to avoid rate limits:
- Poll mode: Traditional polling (default)
- IDLE mode: Real-time IMAP IDLE connections
- Push mode: Gmail Push Notifications via Pub/Sub
- One-way synchronization from source to destination IMAP server
- Optional move mode that deletes emails from source after successful copy
- SSL/TLS support for secure connections
- Credential validation on startup
- Health monitoring with Docker health checks
- Production logging with rotation and structured output
- Portainer compatible for easy web-based management
git clone <repository-url>
cd imap-sync
cp .env.example .envEdit .env with your IMAP server credentials:
# Source IMAP server
HOST_1=imap.gmail.com
[email protected]
PASSWORD_1=your_app_password
# Destination IMAP server
HOST_2=imap.destination.com
[email protected]
PASSWORD_2=your_password
# Sync mode (poll/idle/push) - see CONNECTION-MODES.md
SYNC_MODE=idle # Recommended for Gmail to avoid rate limitsmake build
make start
make logs # Monitor the servicemake status # Check service health
make test # Test IMAP connections| Variable | Description | Example |
|---|---|---|
HOST_1 |
Source IMAP server | imap.gmail.com |
USER_1 |
Source username/email | [email protected] |
PASSWORD_1 |
Source password | app_password_here |
HOST_2 |
Destination IMAP server | imap.destination.com |
USER_2 |
Destination username/email | [email protected] |
PASSWORD_2 |
Destination password | password_here |
| Variable | Default | Description |
|---|---|---|
POLL_SECONDS |
15 |
Polling interval in seconds |
FOLDER |
INBOX |
Folder to synchronize |
MOVE |
false |
Enable move mode (deletes from source) |
SSL1 |
true |
Enable SSL for source server |
SSL2 |
true |
Enable SSL for destination server |
NOTLS1 |
false |
Disable TLS for source server |
NOTLS2 |
false |
Disable TLS for destination server |
# Build and start
make build
make start
# Monitor
make logs
make status
# Stop
make stop- Access Portainer web interface
- Create new stack with name
imap-sync - Copy docker-compose.yml content into the web editor
- Configure environment variables in Portainer's environment section:
HOST_1=imap.gmail.com [email protected] PASSWORD_1=your_app_password HOST_2=imap.destination.com [email protected] PASSWORD_2=your_password POLL_SECONDS=15 FOLDER=INBOX SSL1=true SSL2=true - Deploy the stack
docker build -t imap-sync .
docker run -d \
--name imap-sync \
--env-file .env \
--restart unless-stopped \
-v ./logs:/app/logs \
-v ./data:/app/data \
imap-sync:latest- Server:
imap.gmail.com - Port: 993 (SSL)
- Requirements: App Password (not regular password)
- Setup: Enable 2FA, generate App Password
- Server:
outlook.office365.com - Port: 993 (SSL)
- Requirements: May require App Password
- Server:
imap.mail.yahoo.com - Port: 993 (SSL)
- Requirements: App Password required
- Server: Usually
mail.domain.com - Port: 993 (SSL) or 143 (STARTTLS)
- Requirements: Check with IT administrator
- Never commit
.envfiles to version control - Use App Passwords when available (Gmail, Outlook)
- Rotate credentials regularly
- Use environment variables in production instead of
.envfiles
- Always use SSL/TLS when possible
- Firewall rules to restrict container network access
- VPN connections for accessing internal mail servers
- Test thoroughly with
MOVE=falsebefore enabling move mode - Backup important emails before using move mode
- Monitor logs for any synchronization errors
- Start with small batches to verify behavior
make health # Manual health check
make status # Full service status
docker ps # Check container statusmake logs # Follow logs in real-time
make logs-tail # Show recent logsmake backup # Backup logs, data, and config- Check configuration:
make check-config - Test connections:
make test - Review logs:
make logs - Verify credentials and server settings
- Gmail: Ensure App Password is used, not regular password
- 2FA enabled accounts: Generate and use App Passwords
- Corporate email: Check with IT for IMAP access requirements
- Firewall: Ensure IMAP ports (993, 143) are accessible
- Check folder names: IMAP folder names are case-sensitive
- Network connectivity: Verify both servers are accessible
- Rate limiting: Some servers limit connection frequency
- Disk space: Ensure sufficient space for logs and temporary files
- Rate limiting: Switch to IDLE or Push mode (see CONNECTION-MODES.md)
- Increase polling interval: Set
POLL_SECONDSto higher value (poll mode only) - Resource limits: Adjust Docker memory/CPU limits
- Network latency: Consider server proximity
- Switch to IDLE mode: Set
SYNC_MODE=idlein.env - Use Push notifications: Set
SYNC_MODE=push(requires Google Cloud setup) - Increase poll interval: Set
POLL_SECONDS=60or higher - See detailed guide: Read
CONNECTION-MODES.mdfor full setup instructions
| Error | Cause | Solution |
|---|---|---|
Connection refused |
Server unreachable | Check hostname, firewall |
Authentication failed |
Wrong credentials | Verify username/password |
SSL handshake failed |
SSL/TLS issues | Check SSL settings, certificates |
Folder not found |
Invalid folder name | Verify folder exists, check case |
make debug # Start with shell access
make shell # Access running containermake test # Test IMAP connections
make validate # Validate configuration- Container logs:
docker-compose logs imap-sync - Application logs:
./logs/imapsync.log - Health status:
./data/health
- Check logs for error messages
- Verify configuration with
make check-config - Test connections with
make test - Review troubleshooting section above
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request