Does anyone know of a way to dynamically set the relay host when sending mail through Postfix? At what point does Postfix set the relay host? Is there some way that I can tell Postfix to use a relay host for a particular email (that is outside of global settings)?
Basically, when an email is to be sent to an outbound email address (Gmail, Outlook.com, etc.) I want to be able to choose which relay host to use based on which one has the best deliverability rating. And this could possibly change within seconds so it can't be a "global" postfix setting.
I've thought about creating a content filter which would lookup the "To", find the right relay host and then send the email using another application. However, that seems very awkward to do since we are already in Postfix.
Any help would be greatly appreciated!
Thanks.
Your question is already answered in a more general way: Use different relay in postfix
It is possible to set
transport_maps
which matches recipients domains to relayhosts:Instead of hashfiles, you can use all backends supported, see Postfix lookup table types for example: LDAP, memcache, mysql, pgsql, sqlite and many others.
See the documentation on transport (especially TABLE SEARCH ORDER) to see how postfix finds the values in databases and what keys are used for the search.