Postfix

Flushing the Queue

Postfix is a fairly easy to configure MTA that is compatible with many other utilities, including anti-spam and anti-virus utilities. However, occasionally you may find that for some reason you have a number of emails queued up for delivery.

You can see what is queued , just use:

mailq

If you have a number of messages queued, you can force postfix to attempt to deliver al the queued messages by requesting a flush. To do this, use

postfix flush

Deleting messages from the Queue

A flush attempts to deliver the messages, and leaves any failed messages still in the queue. If you have a number of messages that cannot be delivered, for example, because they have a bad To: address, they rather than having your mail server repeatedly try to deliver the message until the message expires because it gets too old, you can delete the message with:

postsuper -d {Queue ID}

where the value for {Queue ID} is found from the output from mailq.

If you want to delete all the messages, you can use

postsuper -d ALL

However, be a little careful with this, as on a busy server, there may be new messages that have been added to the queue while you have been logged on. A better option may be

postsuper -d ALL deferred

which will only delete messages in the deferred queue.

At times it is necessary to delete messages either from or to a certain address. It is possible to do this by using the `mailq` command to identify the messages. In order to find all messages from an address, the mailq output can simply be passed to grep to find the address. However, looking for messages to a certain address is not so easy, because the mailq output is spread over multiple lines. In order to find all messages to example@example.com (and only to example@example.com, it is necessary to do a bit more work:

mailq | \

Get the list of messages in the queue

head -n +2 | \

Skip over the first line

grep -v '^ *(' | \

Skip the lines that start with (. These are the reason for failure messages.

awk 'BEGIN {RS=""}

Set the record separator so that we can process multiple lines as a single record

{if ($8 = "example@example.com" && $9 == "") print $1}' | \

$8, $9, ... will contain the recipient addresses. Check for $8 as the address you are looking for and $9 empty means only 1 recipient.

tr -d '*!' | \

Remove the comment characters from teh end of the queue ID

postsuper -d -

Read list of Queue IDs to delete from standard input

 

Configuration for Test Servers

If you find that you need to perform testing or development on a system that sends emails, and there is any chance that a "live" email address could find its way into your testing environment, and you do not want to send testing emails to live accounts (which makes you look bad!) then there is a feature that could help you - canonical maps.

In the main.cf file, include a canonical_maps directive:

canonical_maps = regexp:/etc/postfix/canonical_map

Then create the file /etc/postfix/canonical_map with a single entry:

/^.*$/ test.address@your.domain.com

This will re-write any email address that gets passed to postfix, replacing it with the address you specify. Now any email that your test system sends out will end up being delivered to a common testing email address, rather than your customers.

 

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies.