Safe mail archive on ASUSTOR NAS server
I have had a NAS server from ASUSTOR for the last 10 years or so.
But only recently I discovered the FOSS package repository opkg (Entware).
There I found packages to get my personal email off remote servers to the safety of my NAS.
Advantages of handling your mail on your NAS
My original use case was to mirror my Gmail mailbox to a safe storage location, to gradually outphase my Google account. But there are many potential advantages to handling my email directly on the NAS. Just to mention some:
- Privacy - I can always just delete the messages on the server, in the safe knowledge that they will always be there on my NAS and its backups.
- Cost benefits - when using email providers that don’t track you (like Google does), you often have to pay per amount of storage, and with this setup you might just delete everything on the server once you have read it.
- No vendor lock-in — mailbox is stored in open formats like Maildir and processed with open protocols like IMAP and SMTP.
- Mail processing can be automated through scripts and scheduled jobs.
- The setup described here might later be extended to also write and send messages using SMTP (no more need to use various email clients on various platforms).
Follows a detailed description of how to establish a read-only archive mirror of an email account on ASUSTOR NAS.
ASUSTOR NAS
My current NAS model is the AS3302T v2. It runs a customised BusyBox Linux system.
ASUSTOR runs and maintains a package repository with a GUI. As far as I can see, there is no email client available in this repo,
but there is a package named ‘Entware’, which contains opkg, an apt-like package repository.
Install Entware and needed opkg packages
Start with installing Entware from the GUI package repo.
SSH into the NAS and install needed opkg packages.
opkg update
opkg install isync mutt ca-certificates lynx
Mbsync setup
The setup given here is geared for always fetching new messages that appear on the server. Locally on the NAS, it prevents me from ever updating anything, so in effect establishing a read-only archive/backup.
This is the ~/.mbsyncrc file I use:
IMAPAccount gmail
Host imap.gmail.com
Port 993
User <email-address>
Pass "<API key>"
TLSType IMAPS
# help avoid rate limiting
Timeout 60
PipelineDepth 1
IMAPStore gmail-remote
Account gmail
MaildirStore gmail-local
Path ~/Maildir/
Inbox ~/Maildir/INBOX
SubFolders Verbatim
# any labels of the form a/b
# gets converted to a.b dir locally
Flatten "."
Channel gmail
Far :gmail-remote:
Near :gmail-local:
Patterns *
Create Near
# Never delete anything:
Expunge None
Sync Pull
Remove None
Initial download
For the initial download from the remote server, execute this on the NAS:
mbsync -a
If (like in my case) the size of that download is large, you may at some point (after several hours of running the above) get rejected by the server for rate limiting. Not to worry - mbsync handles this just fine, you can simply resume the job after waiting a few hours.
The lines in .mbsyncrc with Timeout and PipelineDepth are meant to some degree to alleviate the rate limiting.
Mailcap for convenient HTML view
To have a more convenient view of messages composed in HTML-like format, I added this to ~/.mailcap
text/html; lynx -dump -force_html -assume_charset=UTF-8 -display_charset=UTF-8 %s; copiousoutput
Mutt
Finally this is my ~/.muttrc config file:
# ===========================================================
# Mutt configuration – BusyBox / NAS edition (read-only viewer)
# ===========================================================
set from = "<email-address>"
set realname = "Your Name"
set imap_user = "<email-address>"
set imap_pass = "<API key>"
set header_cache = ~/.mutt/cache/headers
set message_cachedir = ~/.mutt/cache/bodies
set certificate_file = /opt/etc/ssl/certs/
set mbox_type=Maildir
set folder = ~/Maildir
set spoolfile = +INBOX
# ---- Read-only behavior ----
set read_only = yes # open mailboxes read-only (equiv. to mutt -R)
set move = no # never move read messages
set delete = no # don’t mark for deletion
set record = "" # don’t save sent mail
set postponed = "" # don’t save drafts
set beep = no
set help = yes
# ---- Display preferences ----
set markers = no
set smart_wrap = yes
set fast_reply = yes
set askcc = no
set sort = reverse-date
set date_format="%Y-%m-%d"
set index_format="%4C %Z %{%Y-%m-%d %H:%M} %-20.20F %s"
auto_view text/html
Note that the current version of Mutt on my NAS is 2.1.5. The version of Mutt might influence details in the muttrc file.
Final thoughts
From here, I could automate the fetching of new messages in a crontab entry. For now though, I do it manually. After all, my intention always was to gradually get to the point where I can safely remove all content from Gmail. Given that I started using Gmail in 2004, and had accumulated a large mailbox > 10GB, this had to happen gradually.
With the above setup in place, I am now certain that this is realistic in the near future. I may still depend on the existence of the account for a while, having been silly/lazy enough to use the “Login with your Google account” a couple of places, but even that will be dealt with in due course.
Before you suggest the alternative of a mailbox-to-mailbox migration, e.g. with Protons migration tool, I’ll mention that I once tried that, but ended up deleting the migrated mails, because the Proton mail client became so slow that it was practically unusable. Besides, that would entail paying more for having the account, plus once again leave my private messages somewhere outside of my control.
My new email accounts to replace Gmail - on Posteo, and here on my own domain - could also be archived in the same way in the future. That would allow me to clean up the mailbox on the remote end much more aggressively than I would otherwise feel like (I am slightly the sentimental and definitely cautious type…).
Source code
The code and config files used in this article are also available here: