How can I see the contents of the mail whose ID I get from mailq command?

Better Stack Team
Updated on December 21, 2023

You can see the contents of the mail whose ID you get from the mailq command by using the postcat command. Here’s how you can do it:

 
postcat -q YOUR_MAIL_ID

Replace YOUR_MAIL_ID with the ID of the mail you got from the mailq command.

The system directory /var/spool/postfix is the master directory. Subdirectories of that which matter include active, deferred, bounce, etc. Queued files may be stored using the full file name (like A705238B4C) or with some level of hashing depth (like A/7/05238B4C)

Since Postfix version 2.7, you can also get readable output, by adding the -h and/or -b options:

  • b: Show body content.
  • h: Show message header content.
  • q: Search the Postfix queue for the named files instead of taking the names literally.

So this will show you the entire original message with headers and body:

 
id=YOUR_MAIL_ID
postcat -bh -q $id

Or to show the headers of all queued messages, you could do something like this:

 
mailq | awk '/^ [A-F0-9]+\\s+/ {print $1}' \\ | while read id; do echo $id; postcat -h -q $id; echo; done

Again, replace [YOUR_MAIL_ID](https://serverfault.com/questions/391995/how-can-i-see-the-contents-of-the-mail-whose-id-i-get-from-mailq-command) with the ID of the mail you got from the [mailq](https://serverfault.com/questions/391995/how-can-i-see-the-contents-of-the-mail-whose-id-i-get-from-mailq-command) command.