Postfix: Transport Maps via Third-Party Relay Host

email-servermx-recordpostfix

I have my website and email hosted with a shared host. Unfortunately their servers are using CPanel, so they are limited in their spam protection options.

I also have a VPS that I use for testing and hosting several other bits and pieces (Why don't I use the VPS for websites? I don't want to have to worry about backups!) – I can potentially use this as my MX for my domains, with the shared host as transport maps – I used to run my own dedi and so have Puppet modules ready to go for a mailserver.

The VPS host requires me to use a Postfix mail relay to make sure I'm not spamming from their IP ranges.

Can I use Postfix's transport_maps and relay_host directives together to make my MX forward all mail for my domains to the shared host, but via the VPS host's relay?

A further example of my desired outcome:

  • example.com has an single MX record (for sanity) of vps.example.com
  • vps.example.com receives incoming mail, then consults transport_maps and forwards it to the eventual destination sharedhost.example.com, using the the relay relayvps.example.net as the "next hop"

Best Answer

Personally I wouldn't want to do this. But you could use forwarding addresses on your VPS like this:

a@example.org -> a@subdomain.example.org
b@example.org -> b@subdomain.example.org
...

Then configure your shared host as MX for subdomain.example.org. Then use transport_maps

transport_maps = hash:/etc/postfix/transport

in /etc/postfix/transport put

@subdomain.example.org smtp:[vps.relay.tld]

use postmap to update the lookup-table in transport.db with postmap /etc/postfix/transport.

If you need credentials for the relay you can configure them in /etc/postfix/saslpass

vps.relay.tld username:password

and use postmap /etc/postfix/saslpass to create/update the lookup-table.

On the shared host add the subdomains and forward the mail back to the original addresses. I'm not sure though if the forwarding wouldn't break spam-protection on the VPS.

Related Topic