====== Raspberry Pi NAS: The mail subsystem ====== This page is about configuring the **mail subsystem** on a Raspberry Pi installed with RaspiOS, to be used as NAS and mediacenter. See the main index at **[[raspberrypi_nas]]**. I want a working **mail system** on the NAS, mainly because I want to eventually receive error messages from the various subsystems, think e.g. at the **smartd** daemon watching for S.M.A.R.T. hard drive errors... In the following examples **pimedianas** is the hostname of my Raspberry Pi Mediacenter NAS. I istalled the **postfix** package and configured it as **satellite system** using a **SMTP relay host**. The relevant settings in **/etc/postfix/main.cf** are: myhostname = pimedianas mydestination = $myhostname, localhost.localdomain, localhost relayhost = mail.example.org:587 default_transport = smtp relay_transport = smtp myorigin = $myhostname # Rewrite some sender addresses. sender_canonical_maps = hash:/etc/postfix/sender_canonical_maps # Relay host requires SASL authentication. smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_mechanism_filter = plain, login smtp_sasl_security_options = smtp_tls_security_level = may The content of **/etc/postfix/sender_canonical_maps** will force the **MAIL FROM** on locally generated mails: root pimedianas@example.org root@pimedianas pimedianas@example.org root@localhost pimedianas@example.org root@localhost.localdomain pimedianas@example.org Write the proper info about **localhost** in **/etc/hosts**: 127.0.1.1 localhost.localdomain localhost Finally I had to put my **SMTP credentials** required by the relaying server into **/etc/postfix/sasl_passwd**: mail.example.org pimedianas:MyVerySecretPwd Last but not least, I redirected all the mail for root to my real email address in **/etc/aliases**: root: niccolo@example.org Remember to compile all the files and restart the service: postmap /etc/postfix/sasl_passwd postmap /etc/postfix/sender_canonical_maps newaliases systemctl restart postfix.service Now all the locally generated mails addressed to **root**, **%%root@pimedianas%%**, **%%root@localhost%%** or **%%root@localhost.localdomain%%** should have the **MAIL FROM** rewritten as above and forwarded to the external mailbox.