ImapSync to Gmail Script

Date: Jan 26 2010

Yes sounds easy but I spent sometime looking for the perfect way to import imap mail for any mail server to imap gmail. This is particularly useful if you are transferring your existing mail accounts to google hosted application.

This handles transferring all existing imap folders and even putting your sent mail, spam, drafts, trash into gmail’s special folder naming convention.  Beware this is one sexy script!Its pretty short and sweet. All you need is the program imapsync
(ie. ubuntu: apt-get install imapsync)

Paste the contents of this file into imap2gmail

# nano imap2gmail
# chmod +x imap2gmail

then run it
# ./imap2gmail

#Configure User
#Blank this out if you want to see folder sizes
HIDE="--nofoldersizes --skipsize"
imapsync --syncinternaldates --useheader 'Message-Id' \
--host1 ${SERVER1} --user1 ${UNAME1} \
--password1 ${PWORD1} --ssl1 \
--host2 \
--port2 993 --user2 ${UNAME2} \
--password2 ${PWORD2} --ssl2 \
--authmech1 LOGIN --authmech2 LOGIN --split1 200 --split2 200 ${HIDE} \
--exclude 'Drafts|Trash|Spam|Sent'
#TO Sync Special Folders to Gmail
imapsync --syncinternaldates --useheader 'Message-Id' \
--host1 ${SERVER1} --user1 ${UNAME1} \
--password1 ${PWORD1} --ssl1 \
--host2 \
--port2 993 --user2 ${UNAME2} \
--password2 ${PWORD2} --ssl2 \
--ssl2 --noauthmd5 --split1 200 --split2 200 ${HIDE} \
--folder "Inbox/Sent" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Sent/Sent Mail/' \
--folder "Inbox/Spam" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Spam/Spam/' \
--folder "Inbox/Trash" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Trash/Trash/' \
--folder "Inbox/Drafts" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Drafts/Drafts/' \
Be Sociable, Share!

facebook comments:

6 Comments to “ImapSync to Gmail Script”

  1. imbeowulf 20 April 2010 at 1:36 pm #

    Hey thanks for your script it’s really usefull. Could you explain the last part? [quote]–folder “Inbox/Sent” –prefix2 ‘[Gmail]/’ –regextrans2 ‘s/Inbox\/Sent/Sent Mail/’ \[/quote]What part is the folder from host1 and what part the folder from host2 (gmail)? Could you perhaps give an example where e-mail gets labeled with a non standard gmail label? Thanks in advance.

  2. sázkové kanceláře 24 May 2010 at 12:03 pm #

    great post.So many info in one.Thanks.Wish all the best.

  3. Viktor Petersson 8 July 2010 at 10:47 am #

    While it’s not free, you might still consider Yippiemove ( It’s an online email migration tool similar to imapsync.

    • benleto 21 October 2011 at 11:42 am #

      With the new release of Zimbra 7 migration is built into the interface, one thing i did not see is lotus notes migration. wonder if that tool is still used since we have done many IBM domino lotus note migrations to Zimbra.

  4. AnRkey 15 December 2010 at 7:45 am #

    Thanks, very handy script and easy to hack in to what I needed.

    It was really easy understand too because of the comments in the script.


  5. imapsynciscool 29 March 2012 at 2:36 pm #

    Cool !!!
    I so much didn’t want to script it…
    You saved my day….
    imapsync is great, no need of other fancy stuff ….

Leave a Reply to sázkové kanceláře