Wrote a module to fetch emails and serve them via IMAP
Wrote a module to fetch emails and serve them via IMAP
TL;DR fetchmail to move all emails from email provider to local mailbox that is then served via IMAP by dovecot
Hi, I like being able to switch between email providers easily without having to change my email address (related post). For example right now people have to go through the hassle of going from mygreatusername@some.host to anotherusername@another.host. It's a big barrier because you now have to update that email address everywhere. Imagine having everything on gmail and then moving to startmail, fastmail, posteo, or whatever else.
A solution I was made aware of is to:
- pay for a domain e.g
mydomain.orgfor 10 years (can be cheap) - use their inbuilt email (sometimes free) or pick an email provider that allows custom domains
- pull all the email to server you host
- serve that email
That way, you will have your myname@mydomain.org and switch email providers underneath while keeping all your emails.
Example config
This config uses the module I wrote (maybe something else exists, but I couldn't find it). It pulls emails of myaccount@my.domain from pop.remote.host to my.host and exposes them via IMAPS as myaccount@my.domain on my.host.
Notice that my.domain need not be the same as my.host. This allows me to hide my IMAP server. Somebody looking at the MX record of my.domain won't immediately find the IMAP server.
nix
{ config, ... }:
{
/**
configuration to for fetchmail to retrieve from the remote host
emails will be moved into a the **local** mailbox of a user with the same email address
*/
environment.etc."mail/fetchmailrc" = {
text = ''
poll pop.remote.host protocol pop3 port 995:
user "myaccount@my.domain" with password "passwordWithouQuotes" is vmail here
options fetchall
ssl
mda "dovecot-deliver -d myaccount@my.domain"
'';
user = config.services.email-fetch-serve.daemonUser;
group = config.services.email-fetch-serve.daemonGroup;
};
/**
usernames and passwords used to log into the **self-hosted** IMAP service
Uses same format as /etc/passwd
https://doc.dovecot.org/2.4.3/core/config/auth/databases/passwd_file.html
*/
environment.etc."mail/imap.passwd" = {
text = ''
myAccount@my.domain:{plain}password
'';
user = config.services.email-fetch-serve.daemonUser;
group = config.services.email-fetch-serve.daemonGroup;
};
services.email-fetch-serve = {
enable = true;
sslCertPath = "/var/acme/certs/mydomain.crt";
sslCertKey = "/var/acme/certs/mydomain.key";
fetchmailRcPath = "/etc/mail/fetchmailrc";
imap = {
port = 993;
openFirewall = true;
passdb = "/etc/mail/imap.passwd";
};
};
}