Tag Archives: Proxmox Mail Gateway

Add smtp2go authenticated relay to Proxmox Mail Gateway 9

A bad neighbor on my VPS got my entire subnet blacklisted, so I decided to look into using an SMTP relay to deliver my mail. I decided to use smtp2go. Configuration for Proxmox 9 is different than previous versions, so I had to do a bit of research before I could get authenticated SMTP relay to work properly.

Instead of editing postfix conf directly, you copy the configuration template from /var/lib/pmg/templates to /etc/pmg/templates (create the directory first if it doesn’t exist.) and modify the template file instead. NOTE you must ensure the whole template is there. If you simply paste a configuration snippet into a template file and not the entire thing, all those other configuration lines will not get put into the resulting postfix.conf. Once the template is there, run pmgconfig sync --restart 1 to get PMG to read the template and copy settings out accordingly.

So the full procedure is:

  • Create directory and copy template file over
    mkdir /etc/pmg/templates
    cp /var/lib/pmg/templates/main.cf.in /etc/pmg/templates
  • Modify freshly copied /etc/pmg/templates/main.cf.in template to add authenticated relay (append to the bottom)
relayhost = [mail.smtp2go.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth
  • Create smtp_auth file:
    [mail.smtp2go.com]:587 USERNAME:PASSWORD
  • Set permissions & postmap file:
    chown 600 /etc/postfix/smtp_auth
    postmap /etc/postfix/smtp_auth
  • Sync template settings and restart postfix:
    pmgconfig sync --restart 1

Profit

Configure Proxmox Mail Gateway to use AnyMX relay

I needed to configure Proxmox Mail Gateway to use an authenticated SMTP relay for outgoing mail. There is no way to add a username and password in the PMG GUI; however, you can do it in the command line and it follows standard postfix syntax. Thanks to this post for helping me get it set up: https://forum.proxmox.com/threads/relay-username-and-password.129586

To get it to work you have to drop to the CLI and configure your username and password. Then copy the template file over and make your changes there, as editing postfix directly gets overwritten with subsequent GUI changes.

mkdir /etc/pmg/templates/

cp /var/lib/pmg/templates/main.cf.in /etc/pmg/templates/main.cf.in

create /etc/postfix/smtp_auth and populate it:

relay.host.tld   username:password

Append the following to the /etc/pmg/templates/main.cf.in template:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth
smtp_sasl_security_options = noanonymous

Change permissions to smtp_auth file, run postmap to generate the db with the password, and run pmgconfig to refresh the configuration.

chmod 640 /etc/postfix/smtp_auth
postmap /etc/postfix/smtp_auth
pmgconfig sync --restart 1

This worked for me.