Postfix: We verify recipients from the mailgateway

Translation of the original in Catalan. Read it in: CatalàCastellano

Last May I published a small manual on how to configure a Postfix to act as a 'mailgateway' for another MTA server. Well, today I have added a feature that I initially thought impossible. It is about checking whether the mail we are receiving from outside and that is addressed to a local user exists on the destination server to which we will send the mail. Until now all the mails addressed to @dominilocal.tld were taken and it was the internal MTA that rejected them. The problem with that is that it generates a reply email from the internal MTA to the 'relay' host (mailgateway) and this mail is then tried to be delivered to the original sender. With the consequent problem of the message queue growing, especially if the sender is a problematic email.

diagrama-xarxa.png
Network diagram showing where the mailgateway goes

Well, searching through the Postfix documentation I found that through the /etc/postfix/main.cf file I could use the smtpd_recipient_restrictions command to add a new restriction that would be verifying the recipient (reject_unverified_recipient). But that is not the problem. The problem is, after that, going to verify that recipient on the other host. This is done with the address_verify_local_transport command, where we indicate which is the host that really has the users database.

smtpd_recipient_restrictions =
...
        reject_unverified_recipient
...
address_verify_local_transport=ip_interna_host_MTA

Obviously the internal MTA must be configured in such a way that it does not accept mail for accounts that do not exist. Therefore, it cannot be configured as a dead end, or as they say in Spanish, with a 'catch-all' mail address. So, when an internet MTA sends a mail to the relay server (mailgateway), this one will open a connection against the internal MTA and will verify that the mail account exists through the RCPT TO command; this allows us not to have to enable the feared VERIFY BY command, in order to know whether or not an account exists on the internal server and therefore to reject, if necessary, this mail that is intended to be delivered.