Score:0

Postfix sender_bcc_maps / ignore a specific user

us flag

I have sender_bcc_maps set up and working with postfix so that outgoing mail gets bcc'd to the sender's address. My configuration is more or less:

main.cf

sender_bcc_maps = regexp:/etc/postfix/regexp_sender_bcc

regexp_sender_bcc

/^([^@]+)@[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$/ [email protected]

This works great. Now I have an email address [email protected] that I'd like to exclude from this configuration.

Idea 1: I first tried adding a row to route to a non-existent mailbox

/^nobody.*$/ [email protected]

Predictably, this results in an attempt to bcc that address and a bounceback since it doesn't exist.

Idea 2: Next I tried simply changing the target to an empty string:

/^nobody.*$/

This generates a warning and completely drops the outgoing mail as well:

warning: sender_bcc_maps lookup of [email protected] returns an empty string result
warning: sender_bcc_maps should return NO RESULT in case of NOT FOUND
warning: sender_bcc_maps map lookup problem -- message not accepted, try again later

Idea 3: I then tried routing this mail to a local user:

/^nobody.*$/ nobody@localhost

This somewhat does the job but then all these messages are still delivered to the local mail system.

I'd like to do either one of these - preferring the former:

  • configure sender_bcc_maps to completely ignore a specific sender's address
  • configure postfix to completely discard mail to a specific user
Score:0
us flag

Configure sender_bcc_maps to completely ignore a specific sender's address:

(Credit to Viktor Dukhovni who answered this part of the question via postfix-users)

The Postfix regular expression table is capable of conditional negated pattern matching by using if !/pattern/flags ... endif. In my case the following accomplishes what I am after:

if !/^nobody@/
/^([^@]+)@[a-z-]+\.[a-z]+/ [email protected]
endif

There are also some small improvements to the domain matching part of the pattern since, as was pointed out, the regex is case insensitive by default.

Configure postfix to completely discard mail to a specific user:

The following worked for me to silently discard mail for the specified user. The server is running Ubuntu 20.04.3 LTS but this should work for nearly any Debian flavor:

In /etc/postfix/main.cf:

transport_maps = hash:/etc/postfix/transport

In /etc/postfix/transport:

[email protected] discard:

Then in a shell run:

postmap /etc/postfix/transport
service postfix restart
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.