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:

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]( with the ID of the mail you got from the [mailq]( command.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github