We use mailhog in development / testing and hook it up to postfix. It so that if you mail to an email address ending in .external, it will be relayed to a real server. And, if doesn't we relay it to mailhog.
Postfix configuration /etc/postfix/main.cf:
myhostname = myserver.mydomain.tld
relayhost = real-smtp-relay.mydomain.tld
smtp_generic_maps = pcre:/etc/postfix/smtp_generic_maps.pcre
transport_maps = hash:/etc/postfix/transport
The smtp maps make sure that the .external part is stripped off.
/(.*)\.external$/ $1
The transport maps decide that .external addresses will be relayed to the real SMTP server and the rest will be relayed to mailhog.
.external :
* smtp:127.0.0.1:1025
I would like to migrate this setup to OpenSMTPd but I'm not sure if it can be done. I think the important part is that the PCRE trick is missing.
Or should I use a different approach?