Postfix Cheatsheet

Check the queue

mailq – Check emails queue (then with ! are on hold)

Move all deferred messages to the hold queue

postsuper -h ALL deferred

Release 200 emails from holding back to deferred

mailq | awk ‘ /^[0-9A-F][0-9A-F]/ {print $1}’ | grep ! | head -n 200 | tr -d ‘!’ | postsuper -H –

Delete messages from the hold queue sent by ‘domain.com’

mailq | awk ‘ /^[0-9A-F][0-9A-F]*.*domain\.com$/ {print $1}’ | tr -d ‘!’ | postsuper -d –

Delete messages from the hold queue sent by ‘example@domain.com’

mailq | awk ‘ / example.domain\.com$/ {print $1}’ | tr -d ‘!’ | postsuper -d –

mailq | grep -E “^[A-Z0-9]+” | grep example@domain.com | cut -c1-12 | postsuper -d –

postqueue -p | tail -n +2 | awk ‘BEGIN { RS = “” } / example@domain\.com/ { print $1 }’ | tr -d ‘*!’ | postsuper -d –

Move 100 messages in the hold queue back to deferred

mailq | awk ‘ /^[0-9A-F][0-9A-F]/ {print $1}’ | grep ! | head -n 100 | tr -d ‘!’ | postsuper -H –

Block an IP/Subnet from sending email

Add a /etc/postfix/access file with content like the following. The first line blocks a single IP, the second blocks a subnet

10.2.18 REJECT
10.2.64.1 REJECT

Run ‘postmap /etc/postfix/access’ to create the lookup table.

Add the following line into /etc/postfix/main.cf:

smtpd_client_restrictions = check_client_access hash:/etc/postfix/access, permit

The ‘permit’ statement at the end is very important to allow other email.

Reload postfix to apply the block.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s