Mac mail queue commands

Posted in OSX -

This post is a quick reference for some of the mail server commands for Apple Mac OSX: how to show the queue, flush it, delete everything, delete a particular message, etc.

View the log file

The log file is at /var/log/mail.log, so to view what's going on at the present time use "tail -f" as shown below. This monitors the file, and when new lines are added they'll be displayed as output in your terminal.

tail -f /var/log/mail.log

You'll see stuff like this:

Feb 13 13:13:27 MacBookPro.local postfix/master[46899]: daemon started -- version 2.9.4, configuration /etc/postfix
Feb 13 13:13:27 MacBookPro.local postfix/pickup[46900]: E0B382327BBF: uid=501 from=<chris>
Feb 13 13:13:27 MacBookPro.local postfix/cleanup[46902]: E0B382327BBF: message-id=<20140213001327.E0B382327BBF@MacBookPro.local>
Feb 13 13:13:27 MacBookPro.local postfix/qmgr[46901]: E0B382327BBF: from=<chris@MacBookPro.local>, size=3951, nrcpt=1 (queue active)
Feb 13 13:13:33 MacBookPro.local postfix/smtp[46904]: E0B382327BBF: to=<>,[]:25, delay=6.2, delays=0.53/0.03/2.9/2.7, dsn=2.0.0, status=sent (250 2.0.0 OK 1392250413 xk2si24186201pab.303 - gsmtp)
Feb 13 13:13:33 MacBookPro.local postfix/qmgr[46901]: E0B382327BBF: removed
Feb 13 13:14:27 MacBookPro.local postfix/master[46899]: master exit time has arrived

View the mail queue

To check what's currently in the mail queue, do this:

sudo mailq

And you'll see what's queued:

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
57951232838B*    3977 Thu Feb 13 00:24:51  chris@MacBookPro.local
-- 4 Kbytes in 1 Request.

Flush the mail queue

If you want to flush the mail queue to attempt sending the messages again, do this:

sudo postfix flush

Delete a single message from the mail queue

You can delete a single message from the mail queue by noting its id when viewing the queue. In the example above, the id is 57951232838B. Delete this message like so:

sudo postsuper -v -d 57951232838C

When the message is deleted, you'll see this:

postsuper: Deleted: 1 message

If no messages are deleted, then nothing is output.

Note that if the mail server can't currently connect to the internet to deliver mail (for example your ISP has port 25 firewalled) you'll see messages like "postqueue: warning: Mail system is down -- accessing queue directly" in the log file and when you run mailq.

I've found when getting this paricular message that it's not possible to delete a single message by ID. Perhaps there's another way to do this, but I haven't found one yet, other than to delete all the messages from the queue, as shown next.

Delete all messages from the mail queue

To delete all messages from the mail queue, do this:

sudo postsuper -d ALL

If there's mail in the queue which was deleted, you'll see something like this:

postsuper: Deleted: 1 message

And if there was no mail currently queued, there will be no output from the command.

Related posts: