1

Is there any way to keep an email in the Postfix mail queue for investigation/debugging purposes? I want delay the delivery and the email to be kept in the queue which let's me check it's contents. After I've done that I would flush the queue and let Postfix deliver it. How can I do this?

If it's not possible for a single email - would it be possible to queue all emails for a while?

manifestor
  • 6,079
  • 7
  • 27
  • 39

1 Answers1

3

The HOLD feature should be sufficient for what you ask for, either use it on a message that is not yet delivered:

postsuper -h QUEUEID

Since you cannot know the queue ID in advance and might not be able to see it in the time between postfix queuing the mail and final delivery, I recommend defining the criteria for which messages to hold in advance.

Most smtpd_*_restrictions allow providing a map that can automatically mark certain mails for holding. Sample:

# in main.cf
smtpd_client_restrictions = [..]
    reject_unknown_reverse_client_hostname
    [..]
    check_reverse_client_hostname_access hash:/etc/postfix/badrdns permit

# in /etc/postfix/badrdns
.subdomains.example.com            HOLD one of these is not a spammer

Release or drop mails from the queue after investigating.

postqueue -p
# view a message from queue
postcat -qbhe QUEUEID | less

# deliver previously held
postsuper -H QUEUEID
# drop (DELETE!) a message
postsuoer -d QUEUEID

Do not forget to remove the HOLD rule when done (or you accumulate a giant queue).

anx
  • 8,963
  • 5
  • 24
  • 48
  • Thank you very much for your answer. I don't understand how I can hold `postsuper -h QUEUEID` a message when I don't know the queue ID in advance? – manifestor Feb 25 '21 at 12:22
  • My recommendation to define criteria in advance is my solution for that - if the message might be delivered instantly, use some restriction map to let postfix apply the HOLD action automatically so you do not need to see the queue id in the possibly short window between receipt and delivery. – anx Feb 25 '21 at 14:21
  • once again thank you, but unfortunately this doesn't work - I added `smtpd_recipient_restrictions = check_reverse_client_hostname_access hash:/etc/postfix/hold` to `main.cf`, added all email adresses I want to hold to `/etc/postfix/hold` (content: `some@one.com HOLD`) and created a hash of that file. When I check the queue in the mornings it's always empty. – manifestor Mar 10 '21 at 12:24
  • 2
    If you want to match on a *mail address*, you are going to need to use a different `check_*_access` than I did - I matched on *reverse hostname*. See `man 5 postfix` for a list of all checks you can do in a given restriction list (e.g. `check_recipient_access` matches on the envelope recipient address) – anx Mar 10 '21 at 18:31
  • Thanks for the information! – manifestor Mar 12 '21 at 10:35