4

I need catch email bodies and headers that are sent by postfix on my Ubuntu server.

Could you please explain me, how to catch it?

I know I can do it by postcat (postcat -vq XXXXXXXXXX) when message is in mail queue, but unfortunately I don't know queue ID (XXXXXXXXXX) and when I find it, message is already sent.

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
JEROME
  • 139
  • 1
  • 8

2 Answers2

7
  1. send email
  2. stop postfix
  3. get queue ID
  4. postcat -vq ID

for example:

echo "test message" | mail -s "test" test@example.com
service postfix stop
mailq
postcat -vq C23D82B60024
JEROME
  • 139
  • 1
  • 8
  • 1
    You should probably first stop postfix first and then send the mail. Otherwise it might get sent by the time you stop it – trogper Aug 19 '19 at 20:01
2

if you want to pause delivery of mail to other servers, you could defer smtp transport, do the deed and then undefer it. You will stil get mail delivered to you from other servers.

sudo postconf -e defer_transports=smtp; sudo postfix reload
echo "test message" | mail -s "test" test@example.com
mailq
postcat -vq C23D82B60024
sudo postconf -e defer_transports=; sudo postfix reload; sudo postfix flush

source: nixtips.net

trogper
  • 1,516
  • 1
  • 12
  • 14
  • This worked well for what I needed, however I also had to disable the header_checks line in mail.cf as the mail I was trying to test was being discarded before transport. Also to just get the header I used postcat -vhq as the header was in the MESSAGE CONTENTS otherwise. – jonespm Dec 19 '21 at 21:13