If you want to have a relay for only one recipient or domain on a Postfix mail server, for example to Configure outbound filtering in SpamExperts rather than relay by host, you can use the sender_dependent_relayhost_maps option. This way, you can specify which particular senders you want to relay for and configure it by domain.
This article explains how to configure a relay for certain domains in Postfix, but you could also configure it for just one domain or even for specific mailboxes.
Sender-dependent relay configuration
In the Postfix configuration, you must add or edit the sender_dependent_relayhost_maps parameter to declare the hash file.
You can edit the Postfix configuration file with an editor:
# vi /etc/postfix/main.cf
To add the line and declare the map file in it, the line should contain the following:
sender_dependent_relayhost_maps = hash:/etc/postfix/relay_maps
Next, you can verify the line's configuration with postconf:
# postconf | grep ^sender_dependent_relayhost_maps
You should get the following result, the line entered earlier:
sender_dependent_relayhost_maps = hash:/etc/postfix/relay_maps
Once the file has been declared in the configuration, create the map file with an editor:
# vi /etc/postfix/relay_maps
In it, you must add the domains or senders, one per line, along with the relay destination.
The following example is used to configure a relay for the SpamExperts filter for the domain ejemplo.com and the mailbox usuario@ejemplodos.com:
@ejemplo.com smtp.antispamcloud.com:587
usuario@ejemplodos.com smtp.antispamcloud.com:587
Once you have created the file and added the relay map entries line by line, create the table:
# /usr/sbin/postmap /etc/postfix/relay_maps
Finally, restart Postfix to apply the configuration:
# systemctl restart postfix
Remember, if you have questions about this or any other issue related to your servers at Clouding, feel free to write to soporte@clouding.io We're here for whatever you need. Get in touch!