To extract all destinations (i.e., the recipients
) from the Postfix mail queue (mailq
), you can use the following Bash one-liner:
mailq | awk '/^[A-F0-9]/ {in_msg=1; next} in_msg && /^[ \t]*[^ ]+@[^ ]+/ {print $1}' | sort | uniq
Explanation:
mailq
— shows the mail queue.
awk
: /^[A-F0-9]/
— detects the start of a new message (queue ID line), sets a flag (in_msg=1).
next
— skips the rest of that line.
in_msg && /^[ \t]*[^ ]+@[^ ]+/
— lines after the queue ID that begin with a recipient address.
print $1
— prints the first field (email address).
sort | uniq
— to remove duplicates and sort output.
Example Output
user1@example.com user2@example.org admin@domain.com
Optional: Save to file
mailq | awk '/^[A-F0-9]/ {in_msg=1; next} in_msg && /^[ \t]*[^ ]+@[^ ]+/ {print $1}' | sort | uniq > recipients.txt
Tip: If you need assistance or support for a similar issue, you can contact us ;)