We've been running mail server for a quite of time. The last software was Stalwart Mail Server, unfortunately it's under heavy development. They move so fast then the maintain job is a pain.
We decided to going back to a more mature solution.
1. Should know
Some information that we think you should know when you want to run your own mail server.
1.1. Protocols:
1.2. Formats:
1.3. Software components:
1.4. Resources:
2. Software stack
We're running FreeBSD so we want to run our mail server on it. The solution need to be easy to deploy and maintain.
For small businesses we will not store usernames and passwords in LDAP or SQL databases, we store such information in flat-file databases.
2.1. FreeBSD (operating system)
There is nothing to say. FreeBSD is quite boring, it just works ^^.
We're going to run our mail server in a FreeBSD jail (managed by AppJail). We already have HAProxy as our Load Balancer.
FreeBSD is a good operating system. Please donate to their work.
We just need to make sure our FreeBSD server is up to date.
# pkg update
# pkg upgrade
Create vmail
user and vmail
group. This is the user/group that’s used to access the mails.
# pw useradd vmail -u 5000 -d /home/vmail -s /usr/sbin/nologin -m
Get a free TLS/SSL certificate for your domain from a certificate authority (ZeroSSL, Let's Encrypt..) by acme.sh or Certbot.
We consider Postfix which is more popular but we found that OpenSMTPD is easier to config so we will choose it as our MTA.
We love the config syntax, it remind us about PF.
2.2.1. Install OpenSMTPD
# pkg install opensmtpd opensmtpd-extras
2.2.2. Config OpenSMTPD
2.2.2.1. smtpd.conf
Please read:
Please read it carefully and make your own config file. It's very important.
Modify your file /usr/local/etc/mail/smtpd.conf
:
2.2.2.1.1. TLS/SSL certificate
declare your certificate as follow, pkiname named mail.example.com
:
pki mail.example.com cert "/usr/local/etc/certs/example.com/fullchain.pem"
pki mail.example.com key "/usr/local/etc/certs/example.com/key.pem
2.2.2.1.2. Tables
declare your tables
table aliases file:/usr/local/etc/mail/aliases
table virtuals file:/usr/local/etc/mail/virtuals
table domains file:/usr/local/etc/mail/domains
table credentials file:/usr/local/etc/mail/credentials
table secrets file:/usr/local/etc/mail/secrets
table passwds file:/usr/local/etc/mail/passwds
We will have: aliases
, virtuals
, domains
, credentials
, secrets
and passwds
.
See OpenSMTPD tables below for more information.
2.2.2.1.3. Bind
# STARTTLS port 25
listen on 0.0.0.0 port 25 tls pki mail.example.com
# SMTPS port 465
listen on 0.0.0.0 port 465 smtps pki mail.example.com auth <credentials>
# SUBMISSION port 587
listen on 0.0.0.0 port 587 tls-require pki mail.example.com auth <credentials>
Listen to IPv4 only 0.0.0.0
.
For SMTPS (port 465), SUBMISSION...