Migrate all email from IMAP server to Gmail using OfflineIMAP

OfflineIMAP (github, website) – a great way to migrate email (docs here. Just moved my email from my webhost IMAP-server to a gmail account.

I had some problems connecting to gmail until I enabled “less secure apps” to access my account at https://www.google.com/settings/security/lesssecureapps. Also, Gmail automatically blocked my first access, so I recieved an email that I had to respond to (click a link and verify that it actually was me that tried to access my email – good feature).

Also, OfflineIMAP might complain about unknown certificate fingerprints and print them out. I just added them to the servers that needed them and hoped nobody had manipulated them.

Here is a template for migrating for future reference.

# Offlineimap sample configuration file

[general]
metadata = ~/.offlineimap
accounts = migration
ui = TTYUI

[Account migration]
localrepository = gmail-trg
remoterepository = imap-src

# use sqlite backend rather than plain text
status_backend = sqlite

[Repository imap-src]
type = IMAP
remotehost = imap.yourdomain.com
ssl = yes
remoteport = 993
remoteuser = imap.username
remotepass = imap.password
usecompression = no
maxconnections = 1

# don't write any changes to the imap server
readonly = True

# you might need to fill this in if you use SSL
#cert_fingerprint = 

[Repository gmail-trg]
# You can use Gmail as type, by I had some problems connecting.
type = IMAP
remotehost = imap.gmail.com
ssl = yes
remoteport = 993
remoteuser = gmail.username
remotepass = gmail.password
usecompression = no
maxconnections = 1
readonly = False

# Set cert_fingerprint to whatever you need
#cert_fingerprint = 

# Do not sync [Gmail]/All mail etc folders
folderfilter = lambda foldername: not re.search('^\[Gmail\]', foldername)

New email setup

I think I am going to be quite happy with my new email setup. It has taken a while, actually I’m not quite done yet, but I think it is going to be awesome.

I started writing a lengthy post about this, but it grew to long. So, here’s the tl;dw (too long, did not write) version:

  • I had too much email in my inbox that came from different areas of responsibility.
  • After moving my email from my gmail to my work imap (Exchange), I discovered Exchange does not support keywords (custom flags).
  • I forward my work email to a third party IMAP that supports keywords (Dovecot), but still use my work SMTP.