My internal mail server already:
- Accepts messages from the local subnet for delivery to local users via SMTP
- Accepts messages from authenticated users for delivery to local users via submissions (aka SMTPS)
- Accepts messages from authenticated users for delivery to other internal domains via submissions (aka SMTPS) [Test and live only, not sandbox systems]
- Accepts messages from authenticated users for delivery to other internet domains via submissions (aka SMTPS) [Live only, never sandbox systems and test only during testing sessions]
- Proves mailbox access for authenticated users via IMAPS
Firewall rules determine which hosts can even reach the server, and external access is also via a reverse proxy which has additional rules to block malicious access attempts.
An observant reader will notice that nowhere on that list is any ability to accept messages from other people via the internet. In the (alleged) Good Old Days you could quite happily run an email server on the internet and allow anyone else to route messages to it or even though it and nobody really cared because it was all for the common good and we were all friends and mostly irresponsible adults. Then it turned nasty with the arrival of spammers and the result that many ISPs blocked inbound email or even threatened to terminate customers for running their own email server, and runing an "open relay" to allow anyone to send or route messages is practically a crime. Some ISPs even tried to block their customers using any other email service - which given that basic email is inherently insecure always seemed suspicious.
There is also the related problem of even if you can send email to other servers using SMTP without your ISP blocking it, most mail servers that accept internet email require that messages be signed with things like DKIM and more importantly come from a reputable source otherwise messages get marked as spam or even rejected. And many home / small business ISP networks are not considered reputable sources or even regarded as actively disreputable. So it all gets messy to completely self-host and more to the point for £3.00 per month you can have web, DNS and mail hosting independent of whatever you may get from your ISP. So since mail routing is effectively free with many web hosts, why bother?
I route outbound email via Mythic Beasts (who also host this site) - there's many others who offer similar services - via an encrypted and authenticated submmissions connection so they know it's from my server and users. They apply the DKIM signatures and recipient mail servers see them as a responsible and trustworthy sender so it mostly just works - I have had issues with message recipients in BCC: being rejected or first-time emails to people where they don't have my address already but that's a separate issue.
Inbound internet email is also delivered to Mythic Beasts who apply blocklists and analysis to classify or even delete spam messages. While they could route good, or at least not-bad messages on to my server, that means opening up SMTP and even with firewall restrictions to only accept from Mythic Beasts this can be problematic as we've just discussed. So they deliver mail directly into mailboxes on their server and hold it there for me. This is both good and also a bit of a problem.
| Advantages | Drawbacks |
|---|---|
| If I have technical issues I can still get to messages via their webmail | I have to collect messages from their server and distribute to my users |
| If I have really serious issues then recent messages are still retrievable | Delays in delivery depending on collection method |
| I don't have to care about mailbox limits as old messages are kept on my server not theirs | |
| I can change ISP, hosting provider or even domain and not have to worry about old messages as I already have them. |
To solve the collection issue I use an application to periodically check the external mail server and collect any new messages and deliver them to my internal server. I've been using this approach for many years, first with POP Collector which used the POP3 protocol to deliver to my old Exchange server then after the migration to Ubuntu, Postfix & Dovecot I switched to GetMail to do a very similar job using IMAP. And using systemd timer units the scheduling is a lot more flexible.
While this takes a bit of effort to configure for each user it's proven to be extremly solid and it just works. With only a handful of users I set this up by hand each time, but this could easily be scripted too.
It is possible to have a single external account with all messages delivered to it and then sort it out on final collection, but to allow users to be able to get to recent messages in an emergency I maintain a per-user mailbox at Mythic Beasts.
The process is:
- Install getmai
- Set the passwords on the mailboxes on the external server - and if you let users know them make sure they promise not to change it without telling you first
- Configure getmail collecton for each user with Dovecot as the target
- Configure a systemd timer to run the getmail jobs on the desired schedule
- Validate it works
I set different schedules for different users. There's no point in collected mail overnight when I'm asleep, and during the day it's less frequent as most users have other things to be doing and shouldn't really be looking at personal email. During evenings and weekends the collection jobs most frequently to reduce the delay in receiving messages. As far as the Mythic are concerned it's just a mail client polliing for new messages and it's much lower utilisation than if each user had their all their mail-enabled devices checking for new messages.
Getmail Configuration
Disclaimer: This article is a work in progress. I have getmail working on the current Ubuntu 20.04 mail server but until I complete the migration of a full test server I can't confirm how it's configured on Ubuntu 24.04. I expect it's exactly the same but to be perfectly honest I don't want to spend time now writing up something that's already out of date and may change.
And this is where I pause for now untill untill I get to the Test server migration.