How to transfer mail from your mail server to Zimbra?

“You have to run as fast just to stay in the same place” – this phrase from Lewis Carroll can be safely applied to the work of IT specialists, because trends in the IT industry are changing extremely fast, more than in other industries.

Take, for example, the corporate mail server that has long been successfully implemented, and now no longer fully meets the needs of the modern business, which, in order to stay afloat, needs a comprehensive collaboration system that can easily integrate with other IT systems in the enterprise.

Zimbra

IT managers who want to not only set up a functioning collaboration system in the company, but also save as much as possible of the budget allocated for IT, often pay attention to Zimbra Open-Source Edition. The advantages of Zimbra OSE include the free and completely open source code of the solution, as well as the fact that tens of thousands of enterprises around the world are successfully using it. But it is not enough to implement the system in the enterprise; it is also necessary to transfer all the accumulated correspondence from the old mail server to it.

Mail Transfer

To solve this problem, there are several commercial products with different features at once. However, there is also a free way to transfer emails from the old server to Zimbra, through the use of the imapsync application.

How it works

After installing the application, the transfer of correspondence is carried out by a simple console command, which indicates the address of the source server and the address of the server with Zimbra, as well as the username and password of the user on both mail servers.

imapsync --nosyncacls --subscribe --syncinternaldates \--host1 mail.server.local --user1% Login% --password1% Password% \
--host2 zimbra.server.local --user2% ZimbraLogin% --password2% ZimbraPassword%

Delegated Auth

imapsync supports delegated auth (--authuser1, --authuser2), so it is possibile to migrate accounts even without knowing their passwords. As far as Zimbra is concerned all you need to have to use delegated auth is a globalAdmin or domainAdmin/juniorAdmin account with the “view mail” option enabled.

Automated process

If there are too many users, you can try to automate the process by creating an imap_users file, into which you can then add information about domains, usernames, and passwords to their accounts. For example, like this:

Now all that remains is to write a simple script, give it execution rights and run it. After running the script, the program automatically synchronizes the correspondence between the original mail server and the server with Zimbra. The final script will look something like this:

... imap_users
src_srv = source.server.com
dest_srv = zimbra.server.com
for ((i = 0; i <$ {# users [@]}; i ++))
do
/usr/bin/imapsync --noauthmd5 --syncinternaldates - -buffersize 65535000 --subscribe \
-host1 $ src_srv --ssl1 --user1 $ {users [$ i]} --password1 $ {passwords [$ i]} --nofastio1
--host2 $ dest_srv --ssl2 --user2 $ {users [$ i]} --password2 $ {passwords [$ i]} --nofastio2
done


If you are not going to decommission the old mail server after moving to Zimbra and new correspondence will appear on it, you can automate the execution of this script using cron.

Examples

Below you can find a couple of examples on how to transfer mail from MS Exchange.

  1. Migrating from Exchange 2007/2010/2013 with an admin/authuser account
imapsync ... \
--host1 exchange_server --authuser1 <admin@domain> --user1 <user_alias> --password1 <adminpassword1>
--host2 zimbra_server --user2 ZimbraLogin --password2 ZimbraPassword
  1. Migrating from Exchange 2016 with an admin/authuser account
imapsync ... \
--host1 exchange_server --user1 <user> --authuser1 <admin1> --password1 <adminpassword>
--host2 zimbra_server --user2 ZimbraLogin --password2 ZimbraPassword

Additional Notes

Some people use the Trash folder as an archive. Zimbra, on the other hand, usually cleans up everything under /Trash. In this case you could use “ --regextrans2 “.

Exchange exposes through IMAP some folders that do not contain any usable (from imapsync’s perspective) data, like, for example, Notes, Tasks, Public Folders. It is safe, in this case, to skip those folders, since imapsync would not sync anything anyway.

Possible Issues

This process, however, looks smooth only on paper. IT managers often face unexpected challenges. One of them is the default Zimbra limit of 10 megabytes per email, which can lead to an error when trying to sync emails with large attachments.

This issue can be resolved by increasing the maximum allowable letter size. For example, the command: 

zmprov mcf zimbraMtaMaxMessageSize 52428800 

increases it to 50 megabytes.

Errors can also occur when synchronizing large mailboxes with a huge number of folders and subfolders containing thousands of messages. Due to the large size of such boxes on the Zimbra server side, a disconnection may occur due to the expiration of the session time. That’s why imapsync should be launched on a different machine not to impact Zimbra.

Imapsync tasks/jobs can also be launched in parallel to maximize resource usage. To do so you can use GNU Parallel utility.

Post your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Setting up a password security policy in Zimbra
How to integrate Zimbra Collaboration Suite with Active Directory