When migrating email accounts between IMAP servers, administrators often face the tedious task of transferring entire folder structures while preserving metadata like message dates. Traditional methods using email clients are inefficient for bulk operations and don't always maintain original timestamps.
After extensive testing in production environments, these Unix-compatible solutions prove most effective:
# Using imapsync (Perl-based)
imapsync \
--host1 source.server.com --user1 user@domain.com --password1 secret \
--host2 destination.server.com --user2 user@domain.com --password2 secret \
--syncinternaldates \
--automap
For direct mbox file migration, consider these approaches:
# Using mb2md (requires Perl)
mb2md -s /var/mail/username -d imap://user:pass@server/INBOX
# Alternative with offlineimap
[Repository Local]
type = Maildir
localfolders = ~/Mail
[Repository Remote]
type = IMAP
remotehost = mail.example.com
ssl = yes
remoteuser = username
remotepass = password
For complex migrations with large mailboxes or special requirements:
- Use
--nofoldersizes
when dealing with servers that miscalculate folder sizes - Implement
--split1
and--split2
for handling very large messages - Consider
--delete2
for mirroring deletions from source to destination
Create a bash script wrapper for recurring migrations:
#!/bin/bash
accounts=("user1@domain.com" "user2@domain.com")
for account in "${accounts[@]}"
do
imapsync \
--host1 old.server.com --user1 "$account" --password1 "$(get_password $account)" \
--host2 new.server.com --user2 "$account" --password2 "$(get_password $account)" \
--syncinternaldates --automap --addheader --delete2
done
When encountering problems:
- Verify SSL/TLS settings match between servers
- Check for special characters in folder names
- Monitor for server-side connection limits
- Consider using
--debugimap
for protocol-level inspection
When migrating email accounts between servers, traditional approaches often require manual folder-by-folder transfers or complex scripting. Administrators need robust solutions that handle:
- Complete account migration (Inbox, Sent, custom folders)
- Message date preservation
- Optional single-folder transfers
- Mbox file integration
# Basic syntax:
imapsync \
--host1 source.server.com --user1 user@domain.com --password1 secret \
--host2 dest.server.com --user2 user@domain.com --password2 secret \
--noauthmd5 --ssl1 --ssl2
# Preserve message dates:
imapsync ... --syncinternaldates
# Migrate specific folder only:
imapsync ... --folder "Important Projects"
# Exclude folders:
imapsync ... --exclude "^Deleted|^Spam"
For direct mbox file transfers:
# Using mb2md (requires Perl):
mb2md -s /path/to/mbox -d imap://user:pass@server/INBOX
# With getmail + procmail:
[getmail config]
destination = [procmail]
- Use
--nofoldersizes
for faster initial sync - Implement
--skipemptyfolders
to reduce transfer time - Consider
--split1 1000 --split2 1000
for large mailboxes
#!/bin/bash
# Batch migration script
USERS=("user1@domain.com" "user2@domain.com")
for USER in "${USERS[@]}"; do
imapsync \
--host1 old.example.com --user1 "$USER" --passfile1 /path/to/passfile \
--host2 new.example.com --user2 "$USER" --passfile2 /path/to/passfile \
--automap --addheader --syncinternaldates \
--regextrans2 "s/Sent Items$/Sent/" \
--exclude "Junk|Trash"
done