In this tutorial I will show you Plesk to cPanel Email Migration.
Emails are always a headache when you are doing migration. cPanel to Plesk migration is easy, Plesk have this migration manager and that will take care of everything including mails. cPanel also have 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. Create the domain in the cPanel server and transfer the contents to the document root will complete the content migration. Transfer the database dump to cPanel server and a restoration will complete the database migration also. But how to do the email migration?! Plesk is using Qmail/Postfix and cPanel is using Exim. Two different platform and two different environment. 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!
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 have some limitations and not a good idea to migrate large number of mail accounts):
According to official website, 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 in a DOS box (cmd.exe) or from a batch file.
IMAPCopy is another tool and that will do the same thing. But how these tools works? Simple, these tools are not even checking the mail server environment or platform details. They are syncing the mailboxes using IMAP protocol. When it’s about protocol, it will be same in all platform and the working will be 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 in all platforms. As I mentioned, these tools work with IMAP. So just 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 password 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 password to “Qwe123Qwe”
2) Let’s check if it is done.
The script given below will give you the list of all email accounts in 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 protected] | Qwe123Qwe |
| [email protected] | Qwe123Qwe |
See! It’s done. By running this script you will also get the list of all email accounts in the server. I want you to 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 that we have in the Plesk server. As I mentioned before, If it just one or two email we can manually do it. But suppose we have 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 account that you have to create ( which you already have ).
Note: I assume you already created all domain account in the server.
[email protected] [~]# cat /home/mail.accounts
Now, run the script given below and that will create 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
[email protected] [~]# cd /opt/
[email protected] [/opt]# wget http://home.arcor.de/armin.diehl/imapcopy/imapcopy.tar.gz
[email protected] [/opt]# tar -xvf imapcopy.tar.gz
[email protected] [/opt]# cd imapcopy
[email protected] [/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.
# 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 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 in the Plesk server. (I told you to save the emails in a separate file. Remember? If you forgot, just drag the page up and you can see the for loop script)
Before adding the EMAIL details you have to comment the test accounts under “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 number of emails, just add it manually or please run the script given below.
Note: We have the email account names in – “/home/mail.accounts” file. If your file name is different, make sure to change that in script. Also, I have set all email account passwords (Both in source and destination server) to “Qwe123Qwe”. If you set it 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 if you want to test the working, you can run imapcopy script with “-t” switch.
[email protected] [/opt/imapcopy]# ./imapcopy -t
If you find any connection issues, correct it and then you can start the migration just by running the imapcopy script.
Note: If there are lot of mails or if you are having account with huge size, then make sure to run this in screen session.
[email protected] [/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.
Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.