Move mailboxes between IMAP servers with IMAP TOOLS

IMAP TOOLS is a collection of Perl scripts, allowing you to do many different tasks with IMAP server as well as POP3. In the following article we will guide you to move mailboxes between IMAP servers using IMAP TOOLS.

TipsMake.com - IMAP TOOLS is a collection of Perl scripts, allowing you to do many different tasks with IMAP server as well as POP3. In the following article we will guide you to move mailboxes between IMAP servers using IMAP TOOLS. The content mainly focuses on imapcopy.pl scripts (copies of messages and mailboxes from another IMAP server) and pop3toimap.pl (copies of POP3 messages to IMAP servers). Both scripts support SSL.

>>>Move mailboxes between IMAP servers with IMAPcopy

If you specify port 993 ( 995 for POP3) then an SSL connection will be initialized. If the port number is 143 (110 for POP3) it will try a non-SSL connection. For any other value, ports will test whether SSL is supported. If so, SSL will be used to create the connection, but there will still be a non-SSL connection.

1. Some notes

Here we use two servers:

  1. server1.example.com (source machine)
  2. server2.example.com (target machine)

The request is to transfer the mailbox from sales@example.com (username: sales@example.com , password: secret ) on server1.example.com to the mailbox of sales@example.com on server2.example .com (the same username and password as the other server).

2. Prepare

Before we get started, let's check both mailboxes to see what's in it (you can do this by any email client service like Outlook, Thunderbird or web mail like SquirrelMail we use below.) here).

server1.example.com:

Move mailboxes between IMAP servers with IMAP TOOLS Picture 1Move mailboxes between IMAP servers with IMAP TOOLS Picture 1

server2.example.com:

Move mailboxes between IMAP servers with IMAP TOOLS Picture 2Move mailboxes between IMAP servers with IMAP TOOLS Picture 2

After executing this tutorial, three messages in server1.example.com will appear in server2.example.com .

3. Install IMAP TOOLS

It is not important to install IMAP TOOLS on server1.example.com or server2.example.com , you can even install it on a 3rd machine without any trouble.

We download and install the IMAP TOOLS scripts according to the following directory path:

cd / usr / local /
mkdir imap_tools
cd imap_tools
wget http://www.athensfbc.com/imap_tools/files/imap_tools_V1.105.tar.gz
tar xvfz imap_tools_V1.105.tar.gz

Now execute the Perl scripts:

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

4. Move email between two IMAP servers with imapcopy.pl

We use imapcopy.pl with the following command:

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

So apply the case here to copy the email from sales@example.com on server1.example.com to sales@example.com on server2.example.com as follows:

/usr/local/imap_tools/imapcopy.pl -S server1.example.com/sales@example.com/secret -D server2.example.com/sales@example.com/secret

The output will look like this:

 root @ server1: / usr / local / imap_tools # /usr/local/imap_tools/imapcopy.pl -S server1.example.com/sales@example.com/secret -D server2.example.com/sales@example.com/ secret /usr/local/imap_tools/imapcopy.pl starting Connected to server1.example.com on port 143 Authenticating to server1.example.com as sales@example.com Connected to server2.example.com on port 143 Authenticating to server2.example .com as sales@example.com Number of mailboxes to process: 5 Drafts mailbox is empty thư mục Junk là empty Trash thư mục empty Sent thư mục không có thể Copied 3 thông báo vào INBOX Copied 3 total messages root @ server1: / usr / local / imap_tools # 

Now on the destination server (server2.example.com ) will see the email from server1.example.com :

Move mailboxes between IMAP servers with IMAP TOOLS Picture 3Move mailboxes between IMAP servers with IMAP TOOLS Picture 3

5. Move email from POP3 server to IMAP server with pop3toimap.pl

You can use pop3toimap.pl with the following command:

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

Users_file has the following format:

popUsername password imapUsername password

So need to create the file / usr / local / imap_tools / users_file containing the login details:

en / usr / local / imap_tools / users_file
sales@example.com secret sales@example.com secret

And finally, the command line to copy emai from sales@example.com on POP3 server: server1.example.com to sales@example.com on the IMAP server: server2.example.com is:

/usr/local/imap_tools/pop3toimap.pl -p server1.example.com -i server2.example.com -u / usr / local / imap_tools / users_file

If you get an error:

Trả lời không mong đợi để SELECT INBOX. lệnh: 1 không có thư mục không tồn tại, hoặc phải được đăng đăng vào.
bất thường APPEND câu lệnh: 1 không truy cập được cho APPEND trên INBOX (ACL "i" required)

Fix by opening pop3toimap.pl. .

en /usr/local/imap_tools/pop3toimap.pl

. and create comments at 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 <$ lower; next if $msgnum > $upper; next if $ msgnum> $ upper; } Log("Fetching POP message $msgnum") if $debug; } 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)) {$ copied ++; $ grandTotal ++; Log ("$ copied messages migrated") if $ copied / 100 == int ($ copied / 100); # Delete the message from the POP server if flag delete được đặt deletePOPMsg ($ msgnum, $ p_conn) if $ delete; }} [.] 

Then run the command again:

/usr/local/imap_tools/pop3toimap.pl -p server1.example.com -i server2.example.com -u / usr / local / imap_tools / users_file

The results shown are as follows:

 root @ server1: / usr / local / imap_tools # /usr/local/imap_tools/pop3toimap.pl -p server1.example.com -i server2.example.com -u / usr / local / imap_tools / users_file pop3toimap 1.3 starting There are 1 user to be connected to server1.example.com on port 110 Connected to server2.example.com on port 143 Migrating sales@example.com on server1.example.com to sales@example.com on server2.example.com ( 3 messages) Summary of POP3 -> IMAP migration Users migrated 1 Total messages 3 Total bytes 2912 root @ server1: / usr / local / imap_tools # 

Now on the destination server ( server2.example.com ) will see the email from server1.example.com :

Move mailboxes between IMAP servers with IMAP TOOLS Picture 4Move mailboxes between IMAP servers with IMAP TOOLS Picture 4

Reference links

IMAP TOOLS: http://www.athensfbc.com/imap_tools/

4 ★ | 76 Vote