Point Postfix to a Smart Host for a Specific Domain (Linux)

Problem

When sending mail to a specific domain, tell Postfix to send to a smart host (i.e. gateway or spam filter) rather than directly to the mail server.

tl;dr

Add a line to /etc/postfix/transport:

nano /etc/postfix/transport

recipientdomain.com smtp:filter1.recipientdomain.com

Create a postmap file:

postmap hash:/etc/postfix/transport

Point Postfix to use the created postmap file by adding a line to /etc/postfix/main.cf:

nano /etc/postfix/main.cf

transport_maps = hash:/etc/postfix/transport

Restart postfix:

service postfix restart

Solution

Some large organizations often employ mail gateways, such as Proofpoint to filter incoming email for spam. If you are using a large web email provider, such as Hotmail, Yahoo, or Gmail, their mail servers will often be white-listed. But what if you are trying to send an email to a bank from your office's tiny Postfix mail server? In this case, you will need to point your mail server to the bank's mail gateway.

To do this, you need to create (or edit) your mail lookup table to include the bank's domain, and point any email to their mail gateway, rather than directly to the mail server. This is accomplished via a postmap.

First, you need to create an entry in /etc/postfix/transport file. You can use any file of your choosing as long as you point to it, but by convention, the transport file is used. So, open it:

nano /etc/postfix/transport

Add a line in the format domain.com smtp:smarthost.fqdn.com:port. Unless you are specifying a port (i.e. 587 for SSL connection), you can omit the :port section.

recipientdomain.com smtp:filter1.recipientdomain.com

Save and exit the transport file (Ctrl-O then Ctrl-X if you are using nano). Then, generate a postmap file from your transport configuration:

postmap hash:/etc/postfix/transport

And finally, point Postfix to use the previously generated map any time it restarts:

nano /etc/postfix/main.cf

transport_maps = hash:/etc/postfix/transport

Save and exit the main configuration file, and finally, restart Postfix:

service postfix restart


Was this article helpful?

mood_bad Dislike 0
mood Like 2
visibility Views: 10330