How To Migrate Mailboxes Between IMAP Servers With IMAP TOOLS

Version 1.0
Author: Falko Timme
Follow me on Twitter

This guide explains how you can migrate mailboxes between IMAP servers with IMAP TOOLS. IMAP TOOLS is a collection of Perl scripts that allow you to do various tasks with IMAP servers and also POP3 servers. In this article I will focus on the scripts (copies messages and mailboxes from one IMAP server to another) and (copies POP3 messages to an IMAP server). Both scripts support SSL. If you specify port 993 (995 for POP3) then an SSL connection is initiated. If the port number is 143 (110 for POP3) then it will try a non-SSL connection. With any other value the port will be tested to see if it supports SSL. If so, SSL will be used to make the connection; otherwise a non-SSL connection will be made.

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


1 Preliminary Note

I'm using two servers here:

  • (source)
  • (target)

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


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 IMAP TOOLS Installation

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

We download and install the IMAP TOOLS scripts in the /usr/local/imap_tools/ directory as follows:

cd /usr/local/
mkdir imap_tools
cd imap_tools
tar xvfz imap_tools_V1.105.tar.gz

Now we have to make the Perl scripts executable:

chmod +x /usr/local/imap_tools/*.pl


4 Migrating Email Messages From One IMAP Server To Another IMAP Server With usage is as follows:

/usr/local/imap_tools/ -S host1[:port]/user1/password1 -D host2[:port]/user2/password2

So the command to copy email messages from [email protected] on to [email protected] on is:

/usr/local/imap_tools/ -S[email protected]/secret -D[email protected]/secret

Here's a sample output:

root@server1:/usr/local/imap_tools# /usr/local/imap_tools/ -S[email protected]/secret -D[email protected]/secret
/usr/local/imap_tools/ starting
Connected to on port 143
Authenticating to as [email protected]
Connected to on port 143
Authenticating to as [email protected]
Number of mailboxes to process: 5
   Drafts mailbox is empty
   Junk mailbox is empty
   Trash mailbox is empty
   Sent mailbox is empty
   Copied 3 messages to INBOX
Copied 3 total messages

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


5 Migrating Email Messages From A POP3 Server To An IMAP Server With usage is as follows:

/usr/local/imap_tools/ -p POP3host[:port] -i IMAPhost[:port] -u users_file

users_file has the following format:

popUsername password imapUsername password

So let's create the file /usr/local/imap_tools/users_file that contains the login details:

vi /usr/local/imap_tools/users_file

[email protected] secret [email protected] secret

The command to copy email messages from [email protected] on the POP3 server to [email protected] on the IMAP server is:

/usr/local/imap_tools/ -p -i -u /usr/local/imap_tools/users_file

If you get errors like

Unexpected response to SELECT INBOX. command: 1 NO Mailbox does not exist, or must be subscribed to.
unexpected APPEND response: 1 NO Access denied for APPEND on INBOX. (ACL "i" required)


vi /usr/local/imap_tools/

... and comment out line 123 ($mailbox = 'INBOX' unless $mailbox;) and add line 124 ($mailbox = 'INBOX';):

   foreach $msgnum ( @popMsgList ) {
      if ( $range ) {
         Log("msgnum $msgnum") if $debug;
         next if $msgnum < $lower;
         next if $msgnum > $upper;
      Log("Fetching POP message $msgnum") if $debug;
      $msg = getPOPMsg( $msgnum, $p_conn );

      getFlag( \$msg, \$flag );
      getDate( \$msg, \$date );

      next if $msg eq '';

      #$mailbox = 'INBOX' unless $mailbox;
      $mailbox = 'INBOX';
      selectMbx( $mailbox, $i_conn );

      if ( insertMsg(*msg, $mailbox, $date, $flag, $i_conn ) ) {
         Log("$copied messages migrated") if $copied/100 == int($copied/100);

         #  Delete the message from the POP server if the delete flag is set
         deletePOPMsg( $msgnum, $p_conn ) if $delete;


Then run the

/usr/local/imap_tools/ -p -i -u /usr/local/imap_tools/users_file

command again.

Here's a sample output:

root@server1:/usr/local/imap_tools# /usr/local/imap_tools/ -p -i -u /usr/local/imap_tools/users_file
pop3toimap 1.3 starting
There are 1 users to be migrated
Connected to on port 110
Connected to on port 143
Migrating [email protected] on to [email protected] on (3 messages)

       Summary of POP3 -> IMAP migration

Users migrated  1
Total messages  3
Total bytes     2912


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



Share this page:

3 Comment(s)

Add comment


From: micschk

Since the author of imap tools has decided to ask for a (modest) fee, you'll have to wait for the paypal stuff to be handled.

While waiting, a free port of the scripts can be found here:

From: Anonymous

IMAP TOOLS is commercial.  You should probably mention that.  It would make this post an advert and useless for 99% of people who land here.


Imaptools were free at the time this tutorial was written (2011). The poster that commented before you posted a link from were you can still download the free version from google code.