I launched a new personal website last week, and changed my domain registrar and hosting company in the process. Being concerned how this would affect my primary email account (mail at samtuke dot com), and keen not to lose any of the 10.000+ messages that are stored there, I set about backing them up to a local folder. I also have an ancient Hotmail account, dating from 1997, containing all sorts of childhood contacts and life affecting discussions, and since Microsoft finally decided to allow users gratis use of the IMAP protocl, I decided to back up both email accounts to save time.
Back in the day I used my freedombox to download, sort, and upload to folders all my work emails, in order to avoid races between different mail clients on different platforms in their application of competing filtering rules. Offlineimap, a command line IMAP download utility, served me very well back then, and I’d also used it successfully with Mutt. So again I turned to this tool, this time for the mail backup-backend.
In short, offlineimap downloads messages over the IMAP protocol, and lets you permanently configure a smorgsboard of options such that emails can be syncronised repeatedly, automatically, and without human intervention. It’s ideal for use as a cron job, for example. Installation on Linux distributions is easy:
sudo yum install offlineimap
or
sudo apt-get install offlineimap
After installation, a one-time configuration is necessary. Several criteria must be defined, including:
- Type of syncronisation to use (one way or symmetrical)
- Number of concurrent connections to use
- Location and format for messages saved locally
- Connection security
- Mail server username and password (obviously)
These options and other magic are stored in the offlineimap configuration file. Create it:
nano ~/.offlineimaprc
Then copy paste the example below. Settings are arranged in distinct, reusable “local” and “remote” accounts. There’s some duplication here, but the labels are mercifully intuitive:
[general]
accounts = hotmail, mailatsamtukedotcom
[Account hotmail]
localrepository = local-hotmail
remoterepository = remote-hotmail
[Account mailatsamtukedotcom]
localrepository = local-mailatsamtukedotcom
remoterepository = remote-mailatsamtukedotcom
[Repository local-hotmail]
type = Maildir
localfolders = ~/Mail/hotmail
[Repository local-mailatsamtukedotcom]
type = Maildir
localfolders = ~/Mail/mailatsamtukedotcom
[Repository remote-hotmail]
type = IMAP
remotehost = imap.hotmail.com
remoteuser = samtuke
remotepass = dontyoulook
ssl = yes
cert_fingerprint = 12312d3sad231dsadadsa87dwqdsgvfhhrg1w23w
maxconnections = 4
[Repository remote-mailatsamtukedotcom]
type = IMAP
remotehost = mail.samtuke.com
remoteuser = mail
remotepass = secretsauce
ssl = yes
cert_fingerprint = tw456sd4674uy56pu48vc1qw7c3123aqw8e45f6d
maxconnections = 4
You can add as many accounts as you like, just separate their names by comma on the “accounts” line, and make sure that correct local and remote sections are defined for each.
Once you’re happy with your configuration, create any mail local mail directories that you’ve set for storing the backup emails.
Finally, simply run the program by name on the commandline and you should see your mails flying in:
offlineimap
The command can be run as part of a larger backup script (to compress and encrypt messages once received, for example), or by cron for routine backups. Good luck!
If I try to use imap.hotmail.com, I get ‘ERROR: Could not resolve name ‘imap.hotmail.com’.
How did you obtain the cert_fingerprint value?
Hmm, not sure. I think it “just worked” when I did it – did you find a solution yet?
Hi guys, I had the same problem, and according to here
http://www.limilabs.com/blog/hotmail-imap-pop3-smtp-settings
just change imap.hotmail.com to imap-mail.outlook.com, and it worked. I tried imap.live.com, and it resolved, but connection never came back.
Also, instead of hard-coding the cert, comment out “cert_fingerprint” and use
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
(Whereever that file is on your system)
https://wiki.archlinux.org/index.php/OfflineIMAP#Gmail_configuration
Thanks for the post! I was stuck doing this with fetchmail etc ages ago, this is much better π
Cheers,
Nathan
Nathan: thanks so much for the work around! Glad it’s working well for your mail π
One word: briljant
Works like a charm. Thank you!
Update: On Fedora, add the following line to each [Repository] section of your
~/.offlineimaprc
file to use SSL connections successfully:sslcacertfile = /etc/ssl/certs/ca-bundle.crt