Skip to content

Instantly share code, notes, and snippets.

@maddie
Created September 8, 2022 14:03
Show Gist options
  • Save maddie/4da975e1214a44fbd34ac86e457dc1f5 to your computer and use it in GitHub Desktop.
Save maddie/4da975e1214a44fbd34ac86e457dc1f5 to your computer and use it in GitHub Desktop.
Proxmox SMTP outgoing mail (SMTP) setup
#!/bin/sh
apt-get update && apt-get install -y libsasl2-modules
# only TLS enabled server is supported
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your.name@gmail.com # replace username with your own
SMTP_PASSWORD=hunter2 # replace password with your own
TEST_RECEPIENT=your.name@gmail.com # recepient for test mail
DOMAIN=$(grep "myhostname=" /etc/postfix/main.cf | cut -d= -f2)
echo ${DOMAIN} > /etc/mailname
echo "root@${DOMAIN} ${SMTP_USERNAME}" > /etc/postfix/generic
echo "${SMTP_SERVER} ${SMTP_USERNAME}:${SMTP_PASSWORD}" > /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/generic
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sed -E -i "s/^relayhost =.*/relayhost = ${SMTP_SERVER}:${SMTP_PORT}/g" /etc/postfix/main.cf
echo "smtp_sasl_auth_enable = yes" >> /etc/postfix/main.cf
echo "smtp_sasl_security_options = noanonymous" >> /etc/postfix/main.cf
echo "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" >> /etc/postfix/main.cf
echo "smtp_sender_dependent_authentication = yes" >> /etc/postfix/main.cf
echo "smtp_generic_maps = hash:/etc/postfix/generic" >> /etc/postfix/main.cf
echo "smtp_use_tls = yes" >> /etc/postfix/main.cf
echo "smtp_tls_wrappermode = yes" >> /etc/postfix/main.cf
echo "smtp_tls_security_level = encrypt" >> /etc/postfix/main.cf
echo "smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt" >> /etc/postfix/main.cf
systemctl restart postfix
echo "Test mail from ${DOMAIN}" | mail -s "Proxmox test mail: ${DOMAIN}" ${TEST_RECEPIENT}
@docop
Copy link

docop commented Jun 24, 2023

Hi i try your script on a fresh iso install, no update.. but it never pass up. I did see in some post that now we need to put :
a new line into mail.cf :
default_transport = smtp
but the journalctl -f always report error as:
postfix/smtp[1037]: warning: TLS library problem: error:1408F10B:SSL

: Cannot start TLS: handshake failure
and no mail goes out. Thanks for precision

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment