How To Migrate Mailboxes Between IMAP Servers With imapcopy

Want to support HowtoForge? Become a subscriber!
Submitted by falko (Contact Author) (Forums) on Wed, 2011-10-05 16:36. :: Linux | Email

How To Migrate Mailboxes Between IMAP Servers With imapcopy

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 09/30/2011

This guide explains how you can migrate mailboxes between IMAP servers with imapcopy. imapcopy lets you copy recursively all email messages and folders from one imap account to another. It supports the protocols imap and imaps.

I do not issue any guarantee that this will work for you!


1 Preliminary Note

I'm using two Debian or Ubuntu servers here (the procedure should be the same for other distributions, only the installation of Java - which is required by imapcopy - will differ):

  • (source)
  • (target)

I want to migrate the mailbox (username:, password: secret) on to the mailbox on (username and password are the same as on

A note for Ubuntu users:

Because we must run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing

sudo su


2 Before We Start

Before we start, let's take a look at both mailboxes to see what's in them (you can do this with an email client such as Outlook, Thunderbird, or a web-based email client such as SquirrelMail - I'm using SquirrelMail here).

After the migration, the three messages on should be available on


3 imapcopy Installation

It doesn't matter if we install imapcopy on or - we can even install it on a third, uninvolved server.

Java is needed by imapcopy, so we install the package openjdk-6-jre now. In addition, make sure that unzip is installed so that we can uncompress the imapcopy package:

apt-get install openjdk-6-jre unzip

Next we download and install imapcopy in the /usr/local/imapcopy/ directory as follows:

cd /usr/local/
mkdir imapcopy
cd imapcopy

Now we have to make the /usr/local/imapcopy/ script executable:

chmod +x /usr/local/imapcopy/


4 Doing The Migration

imapcopy usage is as follows:

/usr/local/imapcopy/ protocol://user[:password]@server[:port] protocol://user[:password]@server[:port]

Protocols can be imap or imaps.

If usernames are email addresses, replace @ with %40. So the command to copy email messages from on to on is:

/usr/local/imapcopy/ imap:// imap://

Here's a sample output:

root@server1:/usr/local/imapcopy# /usr/local/imapcopy/ imap:// imap://
2011-09-30 13:28:27,751  INFO ImapCopier - Starting
2011-09-30 13:28:27,751 DEBUG ImapCopier - Parameters length:2
2011-09-30 13:28:27,751 DEBUG ImapCopier - opening conections
2011-09-30 13:28:27,751 DEBUG ImapCopier - opening imap conection to
2011-09-30 13:28:28,737 DEBUG ImapCopier - opening imap conection to
2011-09-30 13:28:28,998 DEBUG ImapCopier - Creating target Folder: Drafts
2011-09-30 13:28:29,030 DEBUG ImapCopier - Copying 0 messages from Drafts Folder
2011-09-30 13:28:29,033 DEBUG ImapCopier - Creating target Folder: Junk
2011-09-30 13:28:29,058 DEBUG ImapCopier - Copying 0 messages from Junk Folder
2011-09-30 13:28:29,059 DEBUG ImapCopier - Creating target Folder: Trash
2011-09-30 13:28:29,061 DEBUG ImapCopier - Copying 0 messages from Trash Folder
2011-09-30 13:28:29,061 DEBUG ImapCopier - Creating target Folder: Sent
2011-09-30 13:28:29,120 DEBUG ImapCopier - Copying 0 messages from Sent Folder
2011-09-30 13:28:29,527 DEBUG ImapCopier - Copying 3 messages from INBOX Folder

On the target server (, you should now see the messages from


5 Links

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by billy (not registered) on Thu, 2014-08-14 13:04.

be careful about any messages that have empty subject lines

they cause the program to crash even if they're in the trash and not completely deleted 

Submitted by Monphpnet (registered user) on Wed, 2011-10-05 23:53.

Google Google Google .......... STOP !!!!!!!!!

Do you known " imapsync " ????????


 Long live free, live Debian, Use First free !

Submitted by Anonymous (not registered) on Thu, 2012-04-19 14:22.
I guess imapsync is no longer completely free to use:
Submitted by Anonymous (not registered) on Fri, 2011-10-07 15:41.
Also you are aware that google code hosts projects that aren't created by google right?  Not crazy the java req though.
Submitted by till (registered user) on Thu, 2011-10-06 19:06.
Imapcopy is released under GPLv2 too ;)