Using this script we can migrate or transfer email address to another provider. We will be doing a complete task on the Linux server. You can use any shell which has imapsync tool.
Note: Please do proper check and understand commands or scripts with a known Linux administrator or web developer before running. You can also try a test run in any test email accounts before executing on live email accounts.
1. Collect the Email account and Password in CSV Format.
2. Create an Email account with the same credentials on the Destination Server.
3. Sync the email using IMAPSYNC (Use any Plain Linux Server for this task)
1. Collect the Email account and Password in CSV Format.
Prepare the email.txt:
We have to create the file “email.csv” with the Emails and password. The format should be as given below.
email1@domainname.com,password1
email2@domainname.com,password2
cat email.csv
email1@abc.com,gPCPL#$700!@
email2@abc.com,gPCPL#$700!@
email3@abc.com,gPCPL#$700!@
email4@abc.com,gPCPL#$700!@
2. Create an Email account with the same credentials on the Destination server.
Now create Email accounts on the Destination Server. The below script works only on the cPanel server. For other mail servers, you can create email accounts manually using a panel or any interface which they support.
1. First create a directory addpop
#mkdir addpop
2. Create file “email.csv” with the Email account and password as mentioned above.
3. Create file “addpop.sh” with the below script.
#vi addpop.sh
!/bin/bash
email=$1
passwd=$2echo “$email, $passwd”
/scripts/addpop –email=$email –password=$passwd;
Next, run the below command to give execute permission to the file.
#chmod +x addpop.sh
root@server.demomonkey.org [addpop ]# ll
total 24K
drwxr-xr-x 2 root root 4.0K Mar 31 07:11 .
dr-xr-x—. 28 root root 4.0K Mar 31 09:31 ..
-rwxr-xr-x 1 root root 167 Mar 30 09:16 addpop.sh
-rw-r–r– 1 root root 165 Mar 30 08:39 email.csv
Now Execute the below-mentioned script (command):
for i in `cat email.csv`; do ./addpop.sh `echo $i |awk -F, {‘print $1,$2’}`; done
Now we created the Email accounts on the destination server.
Also read : How to remove IP from Hotmail blacklist
3. Sync the email using IMAPSYNC (Use any Plain Linux Server for this task)
Now we need to perform the Sync. That we need to execute from any plain test Linux server.
1. I have created a folder “/imapsync
cd /imapsync
2. Now create the file email.csv with the email account and password. The format should be the same as given below.
cat email.csv
email1@abc.com,gPCPL#$700!@
email2@abc.com,gPCPL#$700!@
email3@abc.com,gPCPL#$700!@
email4@abc.com,gPCPL#$700!@
3. Now create the file “imapsync.sh” with the below content. (The file already exists under /imapsync, you need to change the host and host2)
Here the host is the source server and host2 is the destination server
vim imapsync.sh
!/bin/bash
email=$1
passwd=$2echo -e “\n\n\n\e[31;4m $email $passwd \e[0m”
host=mail.grandpolycoats.com
host2=162.144.111.79
imapsync –useuid –noauthmd5 –authmech1 LOGIN –ssl1 –host1 $host –user1 $email –password1 $passwd –sep1 . –prefix1″” –authmech2 LOGIN –ssl2 –host2 $host2 –user2 $email –password2 $passwd –delete2duplicates –subscribe –syncinternaldates –logfile /logs/$1.txt;
4. Now you can execute the final script. Please put it on screen, as it will take time to run.
for i in `cat email.csv`; do ./imapsync.sh `echo $i | awk -F, {‘print $1,$2’}`; done
Now it will start the mail sync. The log will be generated under “/imapsync/LOG_imapsync/host”. For example, the hostname is mail.grandpolycoats.com, a log will be mail.grandpolycoats.com.txt
5. Rename the log file with the current date.
#mv LOG_imapsync/mail.grandpolycoats.com.txt LOG_imapsync/mail.grandpolycoats.com_$(date +%F_%R).txt
Both the source and destination counts can be compared. Once the execution for one email account finished, there would be a tag “Detected 0 errors”. So we can identify if any errors happened to that email account. So once you finished grep the log with this.
Note: Use the below script to find if there the migration/imapsync got failed due to authentication failure.
# for i in
ls
; do echo -e “\n$i”; egrep ‘Folders synced|Start difference host2 – host|Final difference host2 – host1’ $i; done