Postfix (SMTP Relay)
Setting up Postfix as a SMTP relay
[!NOTE] This setup is based on tranquil IT's tutorial.
-
Install and enable postfix and it's dependancies :
apt install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules systemctl enable postfix -
Edit the
nano /etc/postfix/main.cffile and add/change the following lines :relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_use_tls = yes -
Create an application password from your gmail account (2FA needs to be enabled).
-
Create the
/etc/postfix/sasl_passwdfile and add your authentication information :[smtp.gmail.com]:587 USERNAME@gmail.com:MDP_Application -
Fix your file permissions and map the file for postfix :
chmod 400 /etc/postfix/sasl_passwd postmap /etc/postfix/sasl_passwd -
Create a certificate for postfix
cd /etc/ssl/certs openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key-for-smtp-gmail.pem -out cert-for-smtp-gmail.pem cat /etc/ssl/certs/cert-for-smtp-gmail.pem | sudo tee -a /etc/postfix/cacert.pem -
Restart the postfix service
/etc/init.d/postfix reload -
Test and you're done :
echo "Test mail from postfix" | mail -s "Test Postfix" adresse@mail.com
[!IMPORTANT] To make the SMTP server available to your homelab services, you will need to make sure that the
/etc/postfix/main.cffile contains the following entries :mynetworks = 127.0.0.0/8,<your services subnet> inet_interfaces = all
No comments to display
No comments to display