How to Migrate Emails Using imapsync?
What is imapsync?
Imapsync is a method used in website migration. Imapsync copies mailboxes from one server to another during migration. For performing imapsync, the email accounts should use IMAP protocol instead of POP3. Imapsync is a good tool for copying mailboxes because it will not transfer emails which is present on both servers. And also preserves the flags read, sent, unread. That means read will stay read, unread will stay unread, deleted will stay deleted on the new server. To perform imapsync during migration we need to know the following details:
1) IMAP server name at old hosting.
2) Create all the email accounts under new host and
3) List the details of email accounts in the following format
“oldusername” “oldpassword” “newusername” “newpassword”
IMAP is a standard email protocol and it stands for Internet Message Access Protocol. IMAP stores email messages on a mail server but allow the end user to view and manipulate the messages as though they were stored locally on the end user’s computing device(s).
POP3 stands for Post Office Protocol. It is another protocol used to access emails. POP3 downloads email from a server to a single computer then deletes it from the server.
1) Install imapsync
To install imapsync on CentOS you will need to follow the below-given steps.
IMAP sync is written in Perl and is open source, so imapsync isn’t in any of the official CentOS repositories. So at first, we need to install the epel repository.
To install the epel repository follow the below steps:
$ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
$ rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
After installing epel repository, install imapsync using the yum command.
$ yum install imapsync
Now imapsync is installed and now we can proceed with the migration of mailboxes.
We can access an IMAP account with three parameters. The parameters are;
1) The imap server host. It’s a server name or an ip address
2) The username
3) The password
Since the imapsync job is to sync two imap accounts we need to know both server’s hostname, username, and password for proceeding with the syncing. The basic command format for imapsync is
–host1 old.mailserver.com –user1 [email protected] –password1 mypasswd \
–host2 new.mailserver.com –user2 [email protected] –password2 mypasswd
Here we use the –password1 and –password2 switches for the passwords, but this is not a secure way because the passwords would appear in the output of ps -aux. So for ensuring security, we will create two files that contain password and change the permission of the files to 600. After creating the files, we can use the switches –passfile1 and –passfile2 instead of the –password1 and –password2.
Now we can do the migration with the below command:
imapsync –host1 server1.example.com –user1 [email protected] –passfile1 /file name of passwords –host2 server2.example.com –user2 [email protected] –passfile2 /file name of passwords
After imapsync, we can delete the two password files.
On the target server log out of your IMAP account and log back in and you should see the messages from the source server. Because a simple refresh sometimes might not be enough.
If you need any further assistance please contact our support department.