Monday 23 March 2015

Mail migration via Imapsync tool



As an administrator in mail service provider company, there may be a situation where you may want to switch from old email provider to new one.

During migration from old to new setup, you may need to migrate emails from old server to new server.
You can migrate emails easily and freely via Imapsync utility.
Below is short description on working and usage of mails migration via Imapsync.


-To migrate mails from one server to another we use imapsync utility. It connects to server and synchronise mails from source to destination using IMAP protocol.

-Imapsync is a command line utility that incrementally and recursively transfers mails from one mailbox to another.

Imapsync command is available to download from epel.repo.

You need to install imapsync from epel repository on linux or you can download Imapsync from following link.

https://fedorahosted.org/released/imapsync/

Install imapsync from epel repo.

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

On windows, you can download imapsync.exe file and run it from command line with following options.

-----------------------------------------------------------------------------------------------------------

Apart from IMAP access as prerequisites, Imapsync requires minimum 4 parameters which are as follows.
1) Source mailbox email id.
2) Source mailbox password.
3) Destination mailbox email id.
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”


------------------------------------------------------------------------------------------------------------

Important note while synchronizing mail from Gmail to any other destination :

1) Google Mail have restriction that you can maximum download 2.5gb of mails per account per day via IMAP protocol.
2) Google have different directory structure. [Gmail] folder is top hierarchy of gmail folders.

For points mentioned above, we can use following options in Imapsync command:

-You can limit Imapsync tool to synchronize only 2.5gb per day by providing option "--exitwhenover 2500000000" in above command.

- We can provide --ssl1 option to perform imapsync securely.

-We can use --regextrans2 option to migrate mails from source folder to destination folder with different name.

example:
imapsync.sh --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


 you can find man page for imapsync on http://linux.die.net/man/1/imapsync

If you require any more information or help on Imapsync, please add a comment.

No comments:

Post a Comment