While I’ve always believed in my email provider’s data reliability (previously Google, now MXRoute), I feel it’s important to maintain a backup in the case of any unexpected catastrophes.
For my emails, it was just downloading all of them to my email client’s local folders. Pretty simple and straightforward and you’ll be able to quickly access and search through them whenever.
However, with the changing of my computing habits and using my laptop less frequently, I’ve been wanting to set up an alternate backup flow to my remote VPS instead of locally to my laptop.
After much procrastination and research, I’ve made the decision to go with offlineimap for the backup and notmuch to manipulate them on the server.
- Install offlineimap and notmuch
sudo apt install offlineimap notmuch
- Create the
~/.offlineimaprcconfig file. Something like should get you started quickly if you’re using Gmail. You can check out some other examples here.
ui = ttyui
accounts = Gmail
pythonfile = ~/.offlineimap/password.py
localrepository = Gmail-Local
remoterepository = Gmail-Remote
postsynchook = notmuch new
type = Maildir
localfolders = ~/mail/gmail
type = Gmail
remoteuser = [email protected]
remotepasseval = gmailpassword
realdelete = no
maxconnections = 3
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
Note that I’ve stored my password in a separate file
gmailpassword = "YOUR_ACTUAL_PASSWORD_HERE"
Be sure to change the permission and the file ownership:
chmod 600 ~/.offlineimap/password.py
chown user_name:group_name ~/.offlineimap/password.py
notmuchfor the initial configuration
offlineimapto start downloading all the emails. Your first run will probably take awhile.
- Create a cronjob to schedule the download automatically. Since my primary purpose is to backup the emails, I’ve set mine to run once daily:
0 0 * * * offlineimap -o -u quiet
- You can search through all the downloaded emails in
notmuch search "email backup"
notmuch search to:[email protected]
notmuch search date:yesterday
- Then to view specific email thread:
notmuch show thread:000000000000XXXX