Sunday, 8 June 2014

Migrate Email Accounts via Imap Sync

Imapsync is command-line utility for migrating emails between email accounts over IMAP protocol.
Imapsync software is a command line tool that allows incremental and recursive IMAP transfers from one mailbox to another, both anywhere on the internet or in your local network.
"Incremental" means you can stop the transfer at any time and restart it later efficiently.
"Recursive" means the complete folders hierarchy can be copied.
"Command line" means it's not a graphical tool, on Windows you have to run imapsync from a batch file or from command-line directly.


Imapsync performs mail migration when you run it once.If new mails arrive later in your source mailbox you need to re-run imap sync to keep both the email accounts in sync.

 To install Imap Sync on Fedora 

yum install imapsync 

To Install imapsync on Centos 

For 32 Bit systems

wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

For 64 bit Systems
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -Uvh epel-release*rpm

yum install imapsync


Apart from IMAP access as prerequisite Imap sync requires minimum 4 parameters which are
1 .Source Mailbox Email id
2. Source Mailbox Password
3.Destination Mailbox Emailid
4.Destination Mailbox Password

imapsync --host1 <host1-IP> --port1 143 --user1 <olduser1> --password1 <passwd1> --host2 <host2-IP> --port2 143 --user2 <newuser1> --password2 <passwd2>

<host1-IP> IP address or Hostname of Source Mail Server
<oluser1>  Emailid of Source Mailbox user
<passwd1> Password of Source Mailbox user
<host2-IP> IP address or Hostname of Destination Mail Server
<newuser1>  Emailid of Destination Mailbox user
<passwd2> Password of Destination Mailbox user
To avoid incorrect mail synchronization it is preferred to use reconnectretry and timeout parameters.

imapsync --host1 <host1-IP> --port1 143 --user1 <olduser1> --password1 <passwd1> --host2 <host2-IP> --port2 143 --user2 <newuser1> --password2 <passwd2> --reconnectretry1 30 --reconnectretry2 30  --timeout 1200

reconnectretry means if connection to server is lost imapsync will automatically retry to connect after specified interval which is in seconds.
Here we have reconnectretry1 as 30 seconds for source server  reconnectretry2  as 30 seconds for destination server with overall timeout being 1200secs.

If you want to exclude some imap folders like Trash and Spam which are unnecessary you can do it using “–exclude” parameter

imapsync --host1 <host1-IP> --port1 143 --user1 <olduser1> --password1 <passwd1> --host2 <host2-IP> --port2 143 --user2 <newuser1> --password2 <passwd2> --reconnectretry1 30 --reconnectretry2 30  --timeout 1200 –exclude “Trash” --exclude ”Spam”



Mail Migration From Gmail Accounts

Google Mail have restriction that you can maximum download 2.5gb of mails per account per day via IMAP protocol .

imapsync.exe --host1 imap.gmail.com --port1 993 --authmech1 LOGIN --ssl1 --user1 <user1>@gmail.com --password1 <passwd> --host2<host2> --port2 143 --authmech2 LOGIN --user2 <newuser> --password2 <passwd2> --split1 100 --split2 100 --reconnectretry1 30 --reconnectretry2 30 --noauthmd5 --noreleasecheck --timeout 1200 --allowsizemismatch  --exclude "\[Gmail\]$" --regextrans2 "s/Sent Mail/Sent Items/"  --regextrans2 "s/Drafts/Drafts/"   --exclude "\[Gmail\]\/Spam$" --exclude "\[Gmail\]\/Starred$" --exclude "\[Gmail\]\/Important$" --exclude "\[Gmail\]\/Trash$" --exclude "\[Gmail\]\/All\ Mail$"  --prefix1 "[Gmail]/" --exitwhenover 2500000000

Above Command performs mail migration from Gmail.com via IMAPSYNC
--ssl1 is used Secured IMAP from imap.gmail.com
[Gmail] folder is top of Hierarchy of Gmail Folders.
As we need to map Sent Mail to Sent Items we use here regextrans which does the pattern matching as specified
As per Google Policy we have to stop mail migration when it reaches 2.5GB therefore parameter
 --exitwhenover 2500000000 is used to avoid Account Lockout.

In order to perform Batch mail migration for multiple accounts  see the following links
On Windows, see sync_loop_windows.bat batch example.
On Unix, see sync_loop_unix.sh example.
Provide file.txt as input to the above batch or shell script to start bulk mail migration .


No comments:

Post a Comment