diff --git a/content/blog/mail_server_alpine_postfix_dovecot_tutorial.md b/content/blog/mail_server_alpine_postfix_dovecot_tutorial.md index 9952738..7663dab 100644 --- a/content/blog/mail_server_alpine_postfix_dovecot_tutorial.md +++ b/content/blog/mail_server_alpine_postfix_dovecot_tutorial.md @@ -112,7 +112,7 @@ choice. An MX record denotes that your domain is used to send and receive email, and tells other MTAs the domain name of your mail server. We will use `mail.domain.com` for your MX record. For instance, my MX record looks like: -```dns-zone +```bindzone revsuine.xyz. 14400 IN MX 0 mail.revsuine.xyz ``` @@ -124,19 +124,19 @@ same as the IP address of `domain.com`, or an A record if the IP address is not I use a CNAME record because the IP addresses of `mail.revsuine.xyz` and `revsuine.xyz` are the same, so my record is: -```dns-zone +```bindzone mail.revsuine.xyz. 14400 IN CNAME revsuine.xyz ``` If you use an A record, your record may look something like -```dns-zone +```bindzone mail.domain.com. 14400 IN A ip.address.here ``` If you use IPv6, you should also add an AAAA record, e.g.: -```dns-zone +```bindzone mail.domain.com. 14400 IN AAAA ip:address:here:: ``` @@ -178,3 +178,97 @@ following TCP ports are open on your firewall: # Postfix +Postfix is a [mail transport agent](https://en.wikipedia.org/wiki/Message_transfer_agent) (aka SMTP server). [In its +own words](https://www.postfix.org/): + +> Postfix attempts to be fast, easy to administer, and secure. The outside has a definite Sendmail-ish flavor, but the +> inside is completely different. + +## Installing Postfix + +On your server, install Postfix with: + + # apk add postfix + +You likely also want to have Postfix documentation: + + # apk add postfix-doc + +Verify that Postfix is installed by checking its version: + + $ postconf mail_version + +## Configuring Postfix + +Edit `/etc/postfix/main.cf`. + +You should set `myhostname` to the hostname of your server; [in my case, this is +`master.revsuine.xyz`](### A note on my DNS records). + +Now set `mydomain` to the domain you intend to send email from. For instance, my email addresses are +`name@revsuine.xyz`, so `mydomain` is set to `revsuine.xyz`. + +`myorigin` determines the domain name in the `From:` field of locally sent emails. So you could for instance set this +to `revsuine.xyz`. + +`maillog_file` denotes where Postfix's log file is. By default this is `/var/log/messages`; you may want to configure +Postfix to have a dedicated log file like `/var/log/postfix.log`. + +You probably want to have `logrotate` rotate your Postfix log. If there isn't already such a file, you want to create +one at `/etc/logrotate.d/postfix`: + +``` +/var/log/postfix*.log +/var/log/mail*.log +{ + daily + missingok + notifempty + rotate 7 +} +``` + +## Send your first email + +Have the `postfix` service auto-start upon boot, and start it during this session: + + # rc-update add postfix default + # rc-service postfix start + +You can now send an email with the following command: + + $ echo "test email" | sendmail user@externaldomain.com + +Send this email to your email account with an external server, e.g. a gmail account. Note that Protonmail has quite +stringent spam filters and this likely would be rejected by Protonmail, i.e. not even reach your spam folder. + +## Configure email aliases + +You can configure aliases for your mail server. Edit the `/etc/postfix/aliases`[^postfix_aliases_location] file. + +You shouldn't receive mail as root, so configure `root` to have an alias to your user, e.g. + +``` +root: revsuine +``` + +You also *must* have a `MAILER-DAEMON` and `postmaster` alias present: + +``` +MAILER-DAEMON: postmaster +postmaster: root +``` + +Note how you can have referential aliases; mail to `postmaster` is aliased to `root`, which is aliased to `revsuine`, +so ultimately `revsuine` will get `postmaster`'s mail. + +You can continue to populate the aliases file with whatever aliases you want. + + + +[^postfix_aliases_location]: Your aliases file will most likely be in this location by default, but you can run + + $ postconf alias_maps + + to find out where this file should be. +