I'm running OpenSMTPD to receive and send e-mails on FreeBSD. I'm accepting e-mails on a multiple different top-level domains and also send out from multiple different top-level domains (hosting different services on the same server). Now, when my applications send out e-mails then outgoing server hostname will be set correctly since application e-mail library usually sets hostname based on the from parameter value (so for example if from is specified as john@example.org then outgoing e-mail will have example.org as it's hostname).
Now, however when system tries to send out e-mails (or sending out via sendmail under non-privileged user) then server hostname will be used as a hostname. This however, is not correct (not even a real-life domain name) and does not work with DKIM signing.
I can see this under /var/log/maillog where there are errors similar to these:
Jul 30 14:41:38 myserver smtpd[79549]: 0000000000000000 mta delivery evpid=755a2abf780a7383 from=<root@myserver> to=<root@myserver> rcpt=<-> source="-" relay="myserver" delay=2d10h46m40s result="TempFail" stat="No MX found for domain"
Where myserver is the server hostname value. to here is not that important since I should be able to add myserver into /etc/mail/domains and use that in smtpd.conf, however I would like to control from depending on the user sending e-mail. So for example, when non-privileged user john sends e-mail then it would be set as john@example.org automatically.
Is there a way to specify via OpenSMTPD configuration somehow how would the outgoing server hostname be determined based on the from field?