3

I have a quick question. How does one add emails to Postfix's queue without it delivering the emails? I am writing a script to email Postfix statistics (queue count, sent, etc) to our support staff. I want to test it when there are emails in Postfix's queue to see if its working correctly. However, every time I send an email from Postfix it gets delivered. :)

Thanks!

thiesdiggity
  • 437
  • 1
  • 9
  • 22

3 Answers3

4

I came across this other article before I ended up here.

tl;dr:

Just defer emails to a particular transport, in this case SMTP:

pause delivery:

$ sudo postconf -e defer_transports=smtp; sudo postfix reload

un-pause delivery:

$ sudo postconf -e defer_transports=; sudo postfix reload; sudo postfix flush

Mail will queue but not send.

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
jerm
  • 637
  • 3
  • 5
3

Some methods:

  • Use @EightBitTony's approach
  • Use a VM for development and pull the virtual plug to the network
  • Use a firewall rule to drop outgoing packets for port 25.

and the best way:

Sven
  • 98,649
  • 14
  • 180
  • 226
  • 1
    That is the best way to prevent delivery to **a** destination, yes. To prevent delivery in general, stop the smtp(8) daemon. – adaptr May 24 '12 at 09:55
  • @adaptr If you stop the smtp daemon who will add the emails to the queue of the smtp daemon ;-) – ndemou Sep 30 '16 at 16:49
0

Send it to a valid hostname in a domain you own, that you know doesn't run an smtp server. For example, if you own server.domain.example and you know it's not running an smtp server, send them mail to bob@server.domain.example.

Postfix will queue it while it tries to talk to the target smtp server.

This assumes you've not configured postfix to send all mail to another relay, but to deliver directly.

And I'm sure there's a better way, to tell postfix to pause delivery, but hey, there's strength in variation.

EightBitTony
  • 9,311
  • 1
  • 34
  • 46
  • The canonical way to prevent delivery is to stop the smtp(8) daemon by including the following in main.cf: `master_service_disable = smtp` – adaptr May 24 '12 at 09:54