Why to drop mail?
While troubleshooting mailman installation, I've come to a problem: I need to do many tests, but I do not want to disturb recipients of maillist with dozens of test messages. I do not know, if mailman3 has any feature for this kind of testing, but postfix has.
How to drop postfix mail except to whitelisted addresses
First, make sure, you have transport map enabled.
Usually, this line could look like this:
transport_maps = hash:/etc/postfix/transport
Now, create other transport file, my /etc/postfix/blackhole:
mydomain.net :
mymailbox@gmail.com :
* discard:
With this config postfix will deliver to *@mydomain.net and to mymailbox@gmail.com.
run postmap blackhole
to generate /etc/postfix/blackhole.db.
add it to postfix transport with comma (if you already has transport map):
transport_maps = hash:/path/to/other/transport/map, hash:/etc/postfix/blackhole
(or as single element, if you had no transport_maps).
Restart postfix: postfix reload
. You're ready.
Testing
I sent few mails and here is what I have in logs:
Jan 12 09:53:17 list2 postfix/smtp[62239]: DB97418C0808: to=<mymailbox@gmail.com>, relay=gmail-smtp-in.l.google.com[173.194.76.27]:25, delay=0.41, delays=0.03/0.02/0.14/0.22, dsn=2.0.0, status=sent (250 2.0.0 OK 1673517197 g15-20020a056000118f00b002bdd88acc3dsi514695wrx.503 - gsmtp)
Jan 12 09:53:34 list2 postfix/discard[62251]: 7943118C0808: to=<test@test.com>, relay=none, delay=0.02, delays=0.02/0/0/0, dsn=2.0.0, status=sent (test.com)
First is log line for real delivery (relay=
remote mailserver) and second is log line for blackhole delivery, relay=none
).
Top comments (0)