Skip to content

Instantly share code, notes, and snippets.

@tomdaley92
Last active October 15, 2024 19:12
Show Gist options
  • Save tomdaley92/9315b9326d4589c9652ce0307c9c38a3 to your computer and use it in GitHub Desktop.
Save tomdaley92/9315b9326d4589c9652ce0307c9c38a3 to your computer and use it in GitHub Desktop.
Proxmox - Email Alerts Setup (gmail)

Proxmox - Email Alerts Setup (gmail)

  1. SSH into proxmox node and become root user. Run the following commands to download extra software dependencies we'll need.

    apt update
    apt install -y libsasl2-modules mailutils
  2. Enable 2FA for the gmail account that will be used by going to security settings

  3. Create app password for the account.

    1. Go to App Passwords
    2. Select app: Mail
    3. Select device: Other
    4. Type in: Proxmox or whatever you want here
  4. Write gmail credentials to file and hash it. Again, make sure you are root.

    echo "smtp.gmail.com [email protected]:yourpassword" > /etc/postfix/sasl_passwd
    
    # chmod u=rw
    chmod 600 /etc/postfix/sasl_passwd
    
    # generate /etc/postfix/sasl_passwd.db
    postmap hash:/etc/postfix/sasl_passwd
  5. Open the Postfix configuration file with editor of your choice.

    nano /etc/postfix/main.cf
  6. Append the following to the end of the file:

    relayhost = smtp.gmail.com:587
    smtp_use_tls = yes
    smtp_sasl_auth_enable = yes
    smtp_sasl_security_options =
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem
    smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
    smtp_tls_session_cache_timeout = 3600s
    

    IMPORTANT: Comment out the existing line containing just relayhost= since we are using this key in our configuration we just pasted in.

    Screen Shot 2022-09-26 at 10 36 42 AM

  7. Reload postfix

    postfix reload
  8. Test to make sure everything is hunky-dory.

    echo "sample message" | mail -s "sample subject" [email protected]
@aaronwald
Copy link

Thank you

@digitalqualms
Copy link

I installed Proxmox over Debian FWIW, and I ran into this default settings causing errors:

default_transport = error

Commenting it out fixed the issue

@Chia-Chih
Copy link

Chia-Chih commented Oct 11, 2024

Hi, thank you for the most detailed setup you did. If you have a network unreachable error it might be caused by the fact that google smtp server address is now : smtp-relay.gmail.com:25

The address smtp.gmail.com is still functional. Also, if you want to use a different SMTP server, remember to update the SMTP server in /etc/postfix/sasl_passwd.

If you get a "network is unreachable" error and the syslog shows that the SMTP server uses IPv6:

connect to smtp.gmail.com[IPv6]:587: Network is unreachable

Here is my solution:

  1. Open /etc/postfix/main.cf, change inet_protocols = all to inet_protocols = ipv4(or just add it).
  2. Restart postfix using service postfix restart.

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