When working with Postfix's mail queue, the postcat
command is your primary tool for inspecting message contents. For the queue ID A705238B4C
, you would run:
postcat -q A705238B4C
This will output the complete email including headers and body content. For a more readable format, you can pipe the output through less
:
postcat -q A705238B4C | less
If you need to save the email to a file for further analysis:
postcat -q A705238B4C > /tmp/email_A705238B4C.txt
To view only specific parts of the email:
# Headers only
postcat -q A705238B4C | grep -E '^[A-Za-z-]+:'
# Body only (after headers)
postcat -q A705238B4C | sed -n '/^$/,$p'
For emails in the deferred queue, you'll need to specify the full path:
postcat -q /var/spool/postfix/deferred/0/A/A705238B4C
Pro tip: Combine with find to locate messages across all queue directories:
find /var/spool/postfix -name A705238B4C -exec postcat -q {} \;
Extract just the subject line:
postcat -q A705238B4C | grep -i '^Subject:'
Get the recipient addresses:
postcat -q A705238B4C | grep -i '^To:'
If you get "No such file or directory" errors:
- Verify the queue ID exists:
mailq | grep A705238B4C
- Check all queue directories:
find /var/spool/postfix -name A705238B4C
- Ensure you have proper permissions (typically requires root)
When working with Postfix mail servers, administrators often need to inspect queued emails for troubleshooting. The mailq
command provides the queue ID (like A705238B4C
in our example), but doesn't show the actual message content.
The most straightforward method is using Postfix's built-in postcat
command:
postcat -q A705238B4C
This will display the complete email including headers and body. For more readable output:
postcat -vq A705238B4C | less
If postcat
isn't available, you can locate the physical file:
find /var/spool/postfix -name A705238B4C*
Then view it directly:
cat /var/spool/postfix/deferred/0/A705238B4C
To extract just the message body (without headers):
postcat -q A705238B4C | awk '/^$/ {body=1; next} body'
For just headers:
postcat -q A705238B4C | awk '!/^$/ {print} /^$/ {exit}'
For problematic emails that won't deliver:
postsuper -d A705238B4C
This removes the message from queue after inspection.
Here's a bash function to simplify the process:
function read_postfix_email() {
if [ -z "$1" ]; then
echo "Usage: read_postfix_email "
return 1
fi
postcat -vq "$1" | less
}