CLI tool to synchronize emails between Source and Destination IMAP servers over secure port tcp/993 (IMAP over TLS).
Supports single or multiple accounts, CSV-based account lists, dry-run validation, and real-time progress bars.
- IMAP over TLS (port 993) with optional insecure mode for self-signed certificates
- Multi-account sync — migrate multiple mailboxes in a single run
- CSV support — keep server settings in TOML and accounts in a separate CSV file
- Dry-run mode — validate what would be copied without actually transferring emails
- Visual progress bars — real-time feedback with per-mailbox progress
- Mailbox filtering — include/exclude specific mailboxes using wildcards
- Local backup/restore — backup to Maildir and restore to any IMAP server
- Environment variables — load credentials from env vars instead of plaintext
- Parallel accounts — control how many accounts are processed simultaneously
- Credential check — verify account credentials without transferring emails
--config <PATH>(-c): Path to configuration file (TOML)--verbose(-v): Increase logging verbosity--quiet(-q): Decrease logging verbosity--threads <N>(-j): Number of parallel accounts to sync simultaneously (default: 5)--help(-h): Show help message--version(-V): Show version
--dry-run: Validate without copying (available onsync,backup, andrestoresubcommands)
list: List source mailboxes (default)list --from-source: List source mailboxeslist --from-dest: List destination mailboxescheck --from-source: Check source account credentialscheck --from-dest: Check destination account credentialssync: Synchronize mailboxessync --dry-run: Preview what would be synchronizedbackup --from-source --dir <PATH>: Backup source mailboxes to local Maildirbackup --from-dest --dir <PATH>: Backup destination mailboxes to local Maildirbackup --from-source --dir <PATH> --dry-run: Preview backup from sourcerestore --to-source --dir <PATH>: Restore local Maildir to source serverrestore --to-dest --dir <PATH>: Restore local Maildir to destination serverrestore --to-dest --dir <PATH> --dry-run: Preview restore to destination
Create a creds.conf file:
[src]
host="mail.example.com"
user="test@example.com"
password="MyMailPassword"
[dst]
host="mail2.example.com"
user="test2@example.com"
password="MyMail2Password"mail_sync -c creds.conf syncDefine multiple accounts directly in the TOML:
[[accounts]]
src = { host = "mail.example.com", user = "a@example.com", password = "pass1" }
dst = { host = "mail2.example.com", user = "a@example.com", password = "pass1" }
[[accounts]]
src = { host = "mail.example.com", user = "b@example.com", password = "pass2" }
dst = { host = "mail2.example.com", user = "b@example.com", password = "pass2" }mail_sync -c accounts.toml syncKeep server settings in TOML and account credentials in a separate CSV file:
servers.toml:
[settings]
accounts_file = "accounts.csv"
threads = 5
[src]
host = "mail.example.com"
include = "*"
exclude = "Spam,Trash"
[dst]
host = "mail2.example.com"
insecure = true
[folder_map]
"INBOX.Drafts" = "INBOX.rascunhos"
"INBOX.Trash" = "INBOX.lixo"
"INBOX.Sent" = "INBOX.enviadas"accounts.csv (4-column format):
src_user,src_password,dst_user,dst_password
a@example.com,pass1,a@example.com,pass1
b@example.com,pass2,b@example.com,pass2accounts.csv (2-column format — same user/password for both sides):
user,password
a@example.com,pass1
b@example.com,pass2mail_sync -c servers.toml syncTip: The
accounts_filepath is resolved relative to the TOML config file.
Control how many accounts are processed at the same time with --threads (or -j):
mail_sync -c servers.toml -j 3 syncYou can also set the default in the config file:
[settings]
threads = 3If not specified, the default is 5 parallel accounts.
When source and destination servers use different mailbox names, use [folder_map] to translate them automatically:
[folder_map]
"INBOX.Drafts" = "INBOX.rascunhos"
"INBOX.Trash" = "INBOX.lixo"
"INBOX.Sent" = "INBOX.enviadas"If a mapped destination mailbox does not exist, mail_sync will automatically create it via IMAP. If creation fails, the tool reports which mailboxes need to be created manually.
See what would be copied without making any changes:
mail_sync -c servers.toml sync --dry-runOutput example:
Done Dry run complete in 45s — 1247 would be copied | 53 exist | 0 skipped
List all available mailboxes on the source or destination server:
# List source mailboxes (default)
mail_sync -c creds.conf list
# List destination mailboxes
mail_sync -c creds.conf list --from-destVerify credentials without transferring any emails:
# Check source credentials
mail_sync -c creds.conf check --from-source
# Check destination credentials
mail_sync -c creds.conf check --from-destUse include and exclude in the [src] section to control which mailboxes are synchronized:
[src]
host="mail.example.com"
user="test@example.com"
password="MyMailPassword"
include="*"
exclude="INBOX,Sent,Trash"This example syncs all (*) mailboxes except INBOX, Sent and Trash.
If the destination server has an untrusted certificate, add insecure = true:
[dst]
host="mail2.example.com"
user="test2@example.com"
password="MyMail2Password"
insecure=trueLoad credentials from environment variables using user_env and password_env:
[src]
host="mail.example.com"
user="fallback-user"
password="fallback-password"
user_env="MAIL_SYNC_SRC_USER"
password_env="MAIL_SYNC_SRC_PASSWORD"
[dst]
host="mail2.example.com"
user="fallback-user2"
password="fallback-password2"
user_env="MAIL_SYNC_DST_USER"
password_env="MAIL_SYNC_DST_PASSWORD"If the environment variable is set, it overrides the config file value. If not set, the config file value is used and a warning is logged.
Backup emails from an IMAP server to a local Maildir folder:
# backup.toml (same format as sync)
[src]
host="mail.example.com"
user="a@example.com"
password="pass1"
include="*"
[dst]
host="mail2.example.com"
user="a@example.com"
password="pass2"# Backup from source server
mail_sync -c backup.toml backup --from-source --dir ./backups
# Backup from destination server
mail_sync -c backup.toml backup --from-dest --dir ./backups
# Dry-run backup
mail_sync -c backup.toml backup --from-source --dir ./backups --dry-runBackups are stored as standard Maildir format under ./backups/<user>/, preserving flags and folder structure.
Restore emails from a local Maildir backup to any IMAP server:
# Restore to source server
mail_sync -c backup.toml restore --to-source --dir ./backups
# Restore to destination server
mail_sync -c backup.toml restore --to-dest --dir ./backups
# Dry-run restore (validate without copying)
mail_sync -c backup.toml restore --to-dest --dir ./backups --dry-runThe [folder_map] is respected during both backup and restore.
- Visit the Releases page
- Download the binary for your platform:
- Windows (
mail_sync.exe) - Linux AMD64 (
mail_sync_amd64) - macOS (
mail_sync_darwin)
- Windows (
Requirements
Steps
git clone https://github.com/eitatech/mail_sync.git
cd mail_sync
cargo build --releaseThe compiled binary will be available at target/release/mail_sync.