Send emails (SMTP)
Configure Postfix to send emails from the container.
What this tutorial does
The tutorial "Send emails (SMTP)" helps you achieve this goal:
Configure Postfix to send emails from the container.
Postfix + Gmail
-
Install Postfix: apt install -y postfix libsasl2-modules - Choose “Website” during setup.
- Edit /etc/postfix/main.cf and add:
- relayhost = [smtp.gmail.com]:587
- smtp_sasl_auth_enable = yes
- smtp_sasl_security_options = noanonymous
- smtp_sasl_password_maps = hash: /etc/postfix/sasl_passwd
- smtp_tls_security_level = encrypt
- Create /etc/postfix/sasl_passwd with: [smtp.gmail.com]:587 [email protected]:app_password
-
Protect file: chmod 600 /etc/postfix/sasl_passwd -
Generate the hash: postmap /etc/postfix/sasl_passwd -
Restart Postfix: systemctl restart postfix -
Test: echo "Test" | mail -s "Subject" [email protected]