DEV Community

Yaroslav Polyakov
Yaroslav Polyakov

Posted on • Edited on

1

Drop [almost] all outbound mail in postfix for tests

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
Enter fullscreen mode Exit fullscreen mode

Now, create other transport file, my /etc/postfix/blackhole:

mydomain.net :
mymailbox@gmail.com :
* discard:
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

(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)
Enter fullscreen mode Exit fullscreen mode

First is log line for real delivery (relay= remote mailserver) and second is log line for blackhole delivery, relay=none).

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay