Score:0

Does postfix's check_recipient_access map allow for regex?

es flag

I am looking to update my postfix configuration so it restricts the domains to which emails can be sent. I am thinking of using smtpd_recipient_restrictions with check_recipient_access, based on this solution: https://serverfault.com/a/412805 Does this allow for regex? I want to say, only send emails to *@mydomain.com and block everyone else. Something like this:

smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recipients

where recipients will be:

*@mydomain.com PERMIT,
* REJECT,

Is this doable?

Edit: I know this is possible with transportmap, but we already use check_recipient_access to block a few ids, and I would prefer not to introduce another configuration if possible.

Score:2
za flag

Yes, see man 5 regexp_table.

Format will be different, you need to spell out full regexps:

/.*@example\.com/ OK
/.*/ REJECT

or even shorter,

!/.*@example\.com/ REJECT

(default action will be "not found", so it'll continue with the following smtpd_recipient_restrictions items and will be permitted by default).

Save it into a file and hook like this:

smtpd_recipient_restrictions =
...
    check_recipient_access regexp:/etc/postfix/my_regexp_recipients.cf,
...

Postfix allows specifying regexps inline since version 3.7. Your table is very short, so you might end up with

smtpd_recipient_restrictions =
...
    check_recipient_access regexp:{ { !/.*@example\.com/ REJECT } },
...

and no additional files.


Be careful. You need to have other restriction items. Just setting it up like this could make your server an open relay towards *@example.com, if you don't take measures against it in this or other smtpd_*_restrictions parameters (reject_sender_login_mismatch and so on).

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.