Push entire account from one IMAP server to another IMAP server
An alternative is to use mbsync from the isync project. Here is some example configuration for syncing mail from one IMAP server directly to another:
# The IMAP server you wish to copy mails from.
IMAPAccount imap-src-account
Host imap.host.ac.uk
User student0192
# Pass "xxxxx" # if you don't mind storing it in the file; otherwise will prompt
UseIMAPS yes
CertificateFile /etc/ssl/certs/ca-certificates.crt
# The IMAP server you wish to copy mails to.
IMAPAccount imap-dest-account
Host zimbra.corporate.com
User [email protected]
# Pass "xxxxx" # if you don't mind storing it in the file; otherwise will prompt
UseIMAPS yes
CertificateFile /etc/ssl/certs/ca-certificates.crt
# Link IMAP server to remote used below
IMAPStore imap-src
Account imap-src-account
IMAPStore imap-dest
Account imap-dest-account
# ensures that dates of messages will be set correctly
CopyArrivalDate yes
Channel transfer
Master :imap-src:
Slave :imap-dest:
# Transfer all folders
Patterns *
Create Slave
Sync Pull
# important otherwise you will get 'Error: store ... does not support in-box sync state'
SyncState ~/.mail/imap-transfer
You can then run mbsync -l transfer
to list which mail folders will be synchronized.
To actually run the transfer, run mbsync transfer
. The nice thing about this is that you can run that periodically and it will do an efficient sync.
Further notes:
- passwords: You can also specify a
PassCmd
to use a different method of getting the password (e.g. from a token ring). - backups: Most instructions online for mbsync are using this to backup to a local file system. You can even backup to the local file system and then push it to the new server, as described here, but that's more complicated than necessary if you just want to sync the servers
- folder mapping: if you want to transfer folders to a subfolder in the target system (as I did), you can specify this by saying
Slave ":imap-dest:parent-folder/"
in theChannel
configuration.