Imapsync script or How to move more email account easy.

Today I will post a script that show you how to move easy more email account from old mail server to new server.
The story: We have have many account and we now details about every account ( user and password ).

The script

#!/bin/bash
# Example for imapsync massive migration on Unix systems.
# 
# Data is supposed to be in file.txt in the following format
# user001_1;password001_1;user001_2;password001_2
#
# Do not forget to put absolute path
#
# Separator is character semi-colon ; it can be changed
# by any character changing IFS=';'
# Each data line contains 4 columns, columns are 
# parameters for --user1 --password1 --user2 --password2
#
# Replace "imap.server1.org" and "imap.server2.org" 
# with your own hostname values. 
 
# This loop will also create a log file called 
# LOG/log_${u2}_$NOW.txt for each account transfer
# where u2 is just a variable containing the user2 
# account name, and NOW is the current date_time

mkdir -p LOG
 
{ while IFS=';' read  u1 p1 u2 p2
    do 
         { echo "$u1" | egrep "^#" ; } > /dev/null && continue
         NOW=`date +%Y_%m_%d_%H_%M_%S` 
         echo syncing to user "$u2"
         imapsync --host1 imap.server1.org -addheader  --user1 "$u1" --password1 "$p1" \
                  --host2 imap.server2.org --user2 "$u2" --password2 "$p2" \
                  > LOG/log_${u2}_$NOW.txt 2>&1
    done 
} < /etc/rc.d/file.txt
### Do not forget to put absolute path to your file "file.txt" or what ever you name it.

Example for file.txt. ( I put diferent example of user and password )

user001_1;password001_1;user001_2;password001_2
user011_1;password011_1;user022_3;password003_4
sales;passwSals34;sales@ceae.info;passSale7634 

Hope will help you this page!

How to move mails with imapsync from Linux Server to other server or Exchange Mail server.

We have an old Linux mail server and want to upgrade or move mails to other server or new server. How to move easy?  Answer: imapsync.

Example: Move mails from old Linux mail server to new Linux Server:

[root@Linux673]# imapsync –host1 192.168.1.22 –user1 cristian –password1 PASS07432 –host2 192.168.1.1 –user2 cristian@ceae.info –password2 PASS-new87

Example: Move mails from old Linux mail server to new MS Exchange with TLS2

[root@Linux673]# imapsync –host1 mail.old-linux-dm.com –user1 vuser@old-linux-dm.com –password1 PassWORD –tls2 –host2 email.Exchange-Mail.com –user2 new-user@domain.local –password2 PassWORD

Example: Move mails from old Linux mail server to new MS Exchange with  SSL2

[root@Linux673]# imapsync –host1 mail.old-linux-dm.com –user1 vuser@old-linux-dm.com –password1 PassWORD –ssl2 –host2 email.Exchange-Mail.com –user2 new-user@domain.local –password2 PassWORD

You have to change email.Exchange-Mail.com, new-user@domain.local and PassWORD with your local setup.