Credit goes directly to’s blog post –

This method includes a text file containing the users source email address and password as well as the destination (Google) email address and password. Imapsync is the engine to transfer the email and there is a bash script to drive it.

*Allow each user to update their password once email is directed to Google
**Allow less secure apps to allow the transfer to work – – turn off again once complete

Insert the following into a text file (update with live details):


Add as many users as necessary. I found it helpful to add 10 users into a text file at a time to keep an eye on transfers.

Create the script:


Insert the following:


#Configure servers

#Uncomment to hide folder sizes

#Uncomment to do a dry run (no actual changes)

#Uncomment to just sync folders (no messages)

#Uncomment to just connect (no syncs at all)

#Set the path to your imapsync binary

#Users file
if [ -z “$1” ]
echo “No users text file given.”

if [ ! -f “$1” ]
echo “Given users text file \”$1\” does not exist”

{ while IFS=’;’ read u1 p1 u2 p2; do

$imapsync –usecache –tmpdir /var/tmp \
–host1 ${SERVER1} –user1 “$u1” \
–password1 “$p1” –ssl1 \
–host2 ${SERVER2} \
–port2 993 –user2 “$u2” \
–password2 “$p2” –ssl2 \
–regextrans2 ‘s{Sent$}{[Gmail]/Sent Mail}’ \
–regextrans2 ‘s{Sent Items$}{[Gmail]/Sent Mail}’ \
–regextrans2 ‘s{Sent Messages$}{[Gmail]/Sent Mail}’ \
–regextrans2 ‘s{Drafts$}{[Gmail]/Drafts}’ \
–exclude ‘INBOX.Trash|INBOX.spam|INBOX.Apple Mail To Do’

done ; } < $1 [html] Make the script executable: [html] chmod +x [/html] Running the script: [html] ./ users.txt > migrationlog.txt 2>&1 &

A log will be kept of the email transfer.

The script will more than likely take a long time to run so run it in screen.

Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: