User Tools

Site Tools


blog:email_backup

Email backup

Here is some details about my email backup system hosted on my Raspberry Pi. The purpose of this backup system is to allow access to this backup with IMAP.

I use dovecot as IMAP server and mbsync to sync IMAP account on the Pi.

First, install needed packages, Archlinux way :

pacman -S dovecot
yaourt -S isync-git

Dovecot setup

I changed a few things : protocols served, listen address, ports

vim /etc/dovecot/dovecot.conf

Only enable IMAP :

protocols = imap

Disable ipv6 :

listen = *

vim /etc/dovecot/conf.d/10-master.conf

Ports can be changed in “inet_listener imap” and “inet_listener imaps” sections if needed.

Run the service :

systemctl enable dovecot.service
systemctl start dovecot.service

Now we will suppose you are logged with “user” on “domain.net”. It means your IMAP account will be accessible through your dovecot server with email “user@domain.net”.

Maildir setup

Create a directory to put mails in (Maildir format) :

mkdir -p ~/.mail/INBOX
cd ~/.mail

Next, create a mbsync config file for each account you want to sync. In this example, we use login@yahoo.fr :

vim .mbsyncrc1

################################################################################
IMAPAccount login@yahoo.fr
Host imap.mail.yahoo.com
User login
Pass pass
UseIMAPS yes
CertificateFile /etc/ssl/certs/ca-certificates.crt

IMAPStore login@yahoo.fr-remote
Account login@yahoo.fr

MaildirStore login@yahoo.fr-local
Path ~/.mail/INBOX/login@yahoo.fr/
#Inbox ~/.mail/INBOX/login@yahoo.fr/INBOX

Channel login@yahoo.fr
Master :login@yahoo.fr-remote:
Slave :login@yahoo.fr-local:
Patterns *
Create Both
SyncState *
################################################################################

“Inbox” command is commented here. This commands helps mbsync by telling it where is INBOX, because with some providers, it can't find it. Here, yahoo.fr doesn't need it.

Providers needing “Inbox” command :

  • gmail.com
  • free.fr
  • orange.fr

Create directories to store mails about login@yahoo.fr :

mkdir -p INBOX/login@yahoo.fr/{cur,new,tmp}

cur, new and tmp are used to have a valid Maildir folder.

You can reiterate by creating another mbsync config file for another email account.

Ex : .mbsyncrc2, .mbsyncrc3, …

You can check Archlinux wiki page for some details about mbsync : https://wiki.archlinux.org/index.php/Isync

Once your mbsync config files are done, write a little script to update everything :

vim mbsync.sh

#!/bin/bash
cd ~/.mail
for i in $(ls .mbsyncrc*)
do
        mbsync -c ~/.mail/$i -a
done

Your logins and passwords are stored in plain text in the config file, so protect it by making it readable only by your user :

chmod 600 .mbsyncrc*

Update with cron

crontab -e

07,22,37,52 * * * * ~/.mail/mbsync.sh

Here, it is updated every 15 minutes. I use these strange values to avoid running the same time of another cron job.

Access with Thunderbird

Add an email account using “user@domain.net” as email, user as login, domain.net as IMAP server. You have to put a dummy smtp server to let Thunderbird enable the creation of the account.

Once it's ok, you should see all your emails in subdirs like “login@yahoo.fr” in the Inbox.

Remember, as is, it can only be used to receive emails. And every action done on “user@domain.net” is synced. So if you delete some emails, they will be removed from the master server (in this example, yahoo.fr) !

blog/email_backup.txt · Last modified: 2014/02/07 15:13 by popux