Peter Bohner

Migrating Email with mbsync

- 494 words

After fighting with email delivery1 for the n-th time, I finally gave up on doing it myself and decided to switch to mailbox.org for email hosting. Leaving my mailcow instance of 3 years behind was surprisingly easy; After pruning my mail, all I am left with is 4 accounts, 12 aliases and ~5GiB of messages (down from ~20GiB), which I can comfortably merge into one standard mailbox.org account (2.5€/mo), converting 3 of the accounts to aliases2. With some schönrechnen, I even managed to conclude that this switch was free, since I could scale down my VPS, now that it’s storage requirements are lower.


Now to the fun part, mailbox.org does offer an email migration service, but it was very slow3 and did not allow for configuration such as specifying a subfolder. Therefore, I used mbsync instead, whose manpage is thorough but lacks any examples, hence the reason for this short post.

My ~/.config/isyncrc for this one-time migration4 looked like this:

IMAPAccount oldaccount
Host imap.oldhost.example
User you@oldhost.example
Pass "YOURPWHERE"
Port 993
TLSType IMAPS

IMAPAccount newaccount
Host imap.newhost.example.com
User you@newhost.example
Pass "YOURPWHERE"
Port 993
TLSType IMAPS

IMAPStore old-remote
Account oldaccount

IMAPStore new-remote
Account newaccount

Channel migration1
Far :old-remote:
Near :new-remote:old/account1/
Sync Pull
Create Near
CopyArrivalDate yes
Patterns "* INBOX"

Going section by section, the first two define your source accounts, which should be self-explanatory. The next two would allow you to specify some options about how email is accessed through IMAP, however this should work like this for most cases, see the manpage for details.

The final section specifies a channel, which defines how mail will be synced.

  • Far and Near (some documentation online will still use the legacy master and slave terminology), describe the two ends of the pipe, in this case everything in the old-remote, and the old/account1 folders in the new-remote.

  • Sync Pull means that messages (as well as deletions) are propagated from Far to Near, but not the other way around.

  • Create Near creates mail folders, if they do not exist on new-remote.

  • CopyArrivalDate keeps the dates, instead of replacing them with the date of the migration.

  • Patterns * selects all folders on old-remote, except INBOX which needs to be specified manually.

Then simply run mbsync -aV to run all channels and show progress.


  1. Completely unrelated, but Hotmail and T-Online can go take a hike, preferably off some steep cliffs. ↩︎

  2. These were system accounts for nextcloud, paperless-ngx and one other unnamed service, which now have access to my main email. This is not ideal, but a tradeoff I was willing to make. ↩︎

  3. I am sorry to slander my hometown company’s product, but 50 lines of configuration really was better than your startup. The test migration of ~4k messages with very few attachments (this address was only used for registering accounts) took >20min with nothing but an opaque progress bar. ↩︎

  4. You don’t have to put your password in the config file, use Passcmd instead, if you intend to keep this config file around. ↩︎