Hints on email importing

I just worked out (with some significant two-day pain) how to migrate/import a pile of email mailboxes from our old environment.

Lessons learned:

  • Even though our old system was running a not-too-ancient version of Dovecot (same mailbox handler), for whatever reason…
    • the typically-suggested dsync (aka doveadm backup) method was a dismal failure,
    • due to permission, configuration, and possibly network issues.
    • Unless you need to maintain sync’d mailboxes on multiple servers, I wouldn’t go there for a one-time migration process.
  • What works well and easily:
    • Find the old Maildir-format folders (each user should have a folder with at least these subfolders: cur, tmp, new – you want EVERYTHING in there)
    • tar them up and copy to the new server, to a non-protected space (like /tmp)
    • make new mailboxes for all users
    • for each user, run the following. I made a shell script out of it:
      doveadm import -u $1 -U $1 maildir:/tmp/<wherever>/$1 "" all
    • Get rid of all data in non protected space :slight_smile:


Operating system Debian Linux 10
Webmin version 1.981
Usermin version 1.823
Virtualmin version 6.17-3


webmin supports fetchmail, has never failed me for importing email from other hosts. just fix configuration either by webmin module, or by hand (.fetchmailrc).
fixes permissions correctly, can run for as long as you’d like automatically to also fetch newer messages.

if you want to copy folders/maildir, then another way :

  • create user(s) on virtualmin
  • copy all maildir folders (cur, new, tmp, etc…) to new folders
  • fix permissions (chown -R email:vserveruser /path/to/Maildir)
  • for each user run : doveadm force-resync -u $email INBOX

Fetchmail is great for end users. That’s a different use case.

I’m talking about importing all emails from another dovecot-based system, preserving all flags, etc… and ensuring everything is set up correctly. Just for example, the alternate method provided by dimitrist is incorrect on my debian 10-based system:

  • Files are not owned by email:vserveruser but by vserveruser:vserveruser
  • Location of Maildir folder is also system-config-dependent.

doveadm import takes care of all that for us :slight_smile:

  • Correctly imports to the right place
  • Sets permissions properly
  • Creates/preserves indexes as needed

That’s why I like it better than hassling through even more details.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.