5-minute craft, specially useful for those self-hosted Proxmox users who seek sending e-mails to their remote inboxes directly from their nodes:
Assumptions
- Your Proxmox run behind a NAT / is not directly accessible on the Internet so you find trouble sending native system e-mails by default
- You have an already existing e-mail address you would want to make your Proxmox host use to send mails to you
- The connection method to the “sender” e-mail address will be using password authentication
Step by step guide
-
First off, install some dependencies. Run as root:
apt-get update apt-get install libsasl2-modules
-
Edit the
/etc/postfix/main.cf
file like this (replace relayhost’s key value to suit your needs):# See /usr/share/postfix/main.cf.dist for a commented, more complete version myhostname=pve.local smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases #mydestination = $myhostname, localhost.$mydomain, localhost mynetworks = 127.0.0.0/8 inet_interfaces = loopback-only recipient_delimiter = + sender_canonical_classes = envelope_sender, header_sender sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps smtp_header_checks = regexp:/etc/postfix/header_check relayhost = <smtp.mailserver.com>:<smtp_server_port> smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_security_options = noanonymous smtp_tls_wrappermode = yes smtp_tls_security_level = encrypt smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
-
Edit or create the
/etc/postfix/sasl_passwd
file, that will contain the following line (remember to place your own values there):<smtp.mailserver.com>:<smtp_server_port> <sender>@<mailserver.com>:<password>
-
Change file permissions with:
chmod 600 /etc/postfix/sasl_passwd
-
Run:
postmap /etc/postfix/sasl_passwd
-
Edit or create the file
/etc/postfix/sender_canonical_maps
containing:/.+/ <sender>@<mailserver.com>
-
Edit or create the file
/etc/postfix/header_check
with the following:/From:.*/ REPLACE From: <sender>@<mailserver.com>
-
Apply changes by restarting Postfix service:
systemctl restart postfix.service
And that’s it. You can always manually test if it works by running:
echo "This is a test e-mail" | mail -s "Testing" <receiver>@<mailserver.com>
See you next time!