Emails are always a headache when you are migrating. cPanel to Plesk migration is easy; Plesk has this migration manager that will take care of everything, including mails. cPanel also has this migration wizard, but sometimes it won’t work as expected, and that is when we have to do a manual migration. ( From experience, I always suggest doing a manual migration when it is Plesk to cPanel )
So Let’s talk about Plesk to cPanel migration. There are three parts – Content migration, Database migration, and Email migration. The first two parts are easy. Creating the domain in the cPanel server and transferring the contents to the document root will complete the content migration. Transfer the database dump to the cPanel server, and restoration will complete the database migration also. ( I’ll create a doc soon ). But how to do the email migration?! Plesk is using Qmail/Postfix, and cPanel is using Exim. Two different platforms and two different environments. Simply copy-paste the contents won’t work here, and that is not at all an option.
So how is it even possible? Is it possible? Yes, it is possible ( Common! Read the subject line )
Let me introduce two tools that we can use in this situation. ( There is a feature called FetchMail in cPanel Horde, and you can use that tool to fetch the mail accounts, but it also has some limitations and not a good idea to migrate a large number of mail accounts )
According to the official website, imapsync software is a command-line tool that allows incremental and recursive IMAP transfers from one mailbox to another, 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 in a DOS box (cmd.exe) or from a batch file.
IMAPCopy is another tool, and that will do the same thing. But how do these tools work? Simple, these tools are not even checking the mail server environment or platform details. They are syncing the mailboxes using the IMAP protocol. When it’s about protocol, it will be the same on all platforms, and the working will be the same.
Most of the admins are familiarized with imapsync and the working. So let’s see how to do an email migration with “IMAPCopy”.
It’s a Plesk to cPanel migration ( doesn’t mean you can’t follow these steps if the platform is something else. It will work on all platforms. As I mentioned, these tools work with IMAP. So make sure IMAP is working fine, and the port is open. Then you are good to go).
Login to Plesk Server
1) Suppose there are hundreds of accounts, so manually changing passwords is not an option. Simply run the script given below and that will change all mail account passwords to “Qwe123Qwe”
for i in `mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -Ns -e "select concat(mail.mail_name,"@",domains.name) as address from mail,domains,accounts where mail.dom_id=domains.id and mail.account_id=accounts.id order by address"`; do /usr/local/psa/bin/mail -u $i -passwd_type encrypted -passwd 'Qwe123Qwe'; done
That will change all email passwords to “Qwe123Qwe”
2) Let’s check if it is done.
The script below will give you the list of all email accounts on your server + the password.
Plesk:~# mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e "SELECT CONCAT_WS('@',mail.mail_name,domains.name),accounts.password FROM domains,mail,accounts WHERE domains.id=mail.dom_id AND accounts.id=mail.account_id ORDER BY domains.name ASC,mail.mail_name ASC;" +--------------------------------------------+-----------+ | CONCAT_WS('@',mail.mail_name,domains.name) | password | +--------------------------------------------+-----------+ | email@example.com | Qwe123Qwe | | firstname.lastname@example.org | Qwe123Qwe | +--------------------------------------------+-----------+
See! It’s done. By running this script, you will also get the list of all email accounts on the server. Please note this and store this in a separate file because we will need this list later.
So that’s all we need from the Plesk server. Now let’s login to our cPanel server and follow the rest of the steps.
Login to cPanel Server
1) In this cPanel server, we have to create all emails in the Plesk server. As I mentioned before, we can manually do it if it is just one or two emails. But suppose we have a lot of email accounts. So we have to write a script for that, and I already did. First, create a file called “/home/mail.accounts” with the name of all email accounts you have to create ( which you already have ).
( Note: I assume you already created all domain account on the server )
root@cPanel [~]# cat /home/mail.accounts email@example.com firstname.lastname@example.org
Now, run the script given below and that will create an emails account given in “/home/mail.accounts” with the password “Qwe123Qwe”
for i in $(cat /home/mail.accounts); do /scripts/addpop $i 'Qwe123Qwe'; done
So now we created the same email account in our cPanel server now it’s time to sync the mail contents with IMAPCopy.
2) Let’s install IMAPCopy
root@cPanel [~]# cd /opt/ root@cPanel [/opt]# wget http://home.arcor.de/armin.diehl/imapcopy/imapcopy.tar.gz root@cPanel [/opt]# tar -xvf imapcopy.tar.gz imapcopy/ imapcopy/imapcopy imapcopy/ImapCopy.cfg root@cPanel [/opt]# cd imapcopy root@cPanel [/opt/imapcopy]# ls ./ ../ imapcopy* ImapCopy.cfg
As you can see, it’s a simple tool. Just have two files. “imapcopy” is the shell executable, and “ImapCopy.cfg” is the configuration file.
3) Open the “ImapCopy.cfg” and you can see the sections below.
############## # Sourceserver ############## SourceServer localhost SourcePort 143 ################### # Destinationserver ################### DestServer localhost DestPort 143 ############################# # List of users and passwords ############################# # SourceUser SourcePassword DestinationUser DestinationPassword Copy "foo" "foosrcpw" "foo" "foodestpw" Copy "bar" "barsrcpw" "bar" "test"
4) You already know what to do. Under the “Sourceserver” section, give the source server IP/Hostname and IMAP port. In this case, you don’t have to change anything because the source server is this machine. Then under the “Destinationserver” section, give the Plesk server IP/Hostname and IMAP post. ( You can run this same script from the Plesk server. Just need to change the source and destination server configurations )
5) Then, you can see the section “List of users and passwords”. Here you have to specify the EMAIL user account and password details ( Both source and destination ). We already have the list of email accounts and passwords that you have on the Plesk server. ( I told you to save the emails in a separate file. Remember? If you forgot, drag the page up, and you can see the for loop script )
Before adding the EMAIL details, you must comment on the test accounts under the “List of users and passwords” section.
sed -i 's/^Copy/#Copy/g' /opt/imapcopy/ImapCopy.cfg
Now you can add the email details. If you have just a number of emails, add it manually or run the script below.
( Note: We have the email account names in file – “/home/mail.accounts”. If your file name is different, make sure to change that in the script. Also, I have set all email account passwords ( Both in source and destination server ) to “Qwe123Qwe”. If you set it to something else, make sure to change that also. )
for i in $(cat /home/mail.accounts); do echo "Copy "$i" "Qwe123Qwe" "$i" "Qwe123Qwe"" >> /opt/imapcopy/ImapCopy.cfg; done
Now you are all set. Before starting the migration, you can run the imapcopy script with the “-t” switch to test the work.
root@cPanel [/opt/imapcopy]# ./imapcopy -t
If you find any connection issues, correct it, and then you can start the migration by running the imapcopy script.
( Note: If there are many mails or if you have a huge account, then make sure to run this in a screen session. )
root@cPanel [/opt/imapcopy]# ./imapcopy
That’s it! You can see it migrating each and every account just like that. After the migration, you can verify, and I’m sure there will be a smile on your face because you just completed a Plesk to cPanel email migration!