Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Remove undeliverable local mail System
Some days ago, I noticed that I have a bunch of yet unseen error messages about undeliverable e-mail in my daily.out log file: Postqueue was unable to send mail to myusername@mymachinename.local?! Running no mail services on my machine, the situation was quickly clear -- developing php-baesd websites locally, I have tested a form mailer with some wrong parameters, so the actual mail server was not found. My research to get rid of these mails brought up an easy command (mailq -q) which, when run as root, would theoretically flush any local mail and thereby delete the undeliverable. The only problem was that when I tried it, the command only produced error messages about the mail system being down.

The final solution was as easy as the command itself. Simply open up another Terminal session and start up sendmail temporarily by typing sudo sendmail. The prompt will stay empty because sendmail waits for its input, but that doesn't matter at this time. Switch back to your first session, execute the command sudo mailq -q, and your local mailqueue will be emptied. End this session, switch to the one which has sendmail running, type Control-C to stop sendmail, and you are done.
  • Currently 1.80 / 5
  You rated: 5 / 5 (5 votes cast)

Remove undeliverable local mail | 5 comments | Create New Account
Click here to return to the 'Remove undeliverable local mail' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Remove undeliverable local mail
Authored by: nigelbruin on Nov 30, '06 05:09:40PM

I use "sudo postsuper -d ALL" in such cases.

[ Reply to This | # ]
Use postsuper not mailq to delete messages
Authored by: Mike F. on Nov 30, '06 07:53:13PM

sudo postsuper -d ALL is indeed much better!

I just happened to have a situation where my local mailserver had a couple of undeliverable mails in its queue which originated from a PHP script I was testing. The mails where undeliverable because the recipient mail server refuses to accept mail from my IP without authentication (which is perfectly fine). All sudo mailq -q did was to try to resend the defered messages which didn't help in any way.

Not being a sendmail or postfix guru this tip came in very handy (and timely too).


[ Reply to This | # ]
Remove undeliverable local mail
Authored by: gunnmjk on Dec 02, '06 06:51:38PM

I'm trying to figure out my my local mail isn't being sent out. I think that there might be a delay, or something else wierd.

I thought that you don't need to start postfix if it is created locally, because MacOS termporarily enables postfix for 60 seconds.

For some reason, typing "mail" gives me "No mail for username" but "sudo mailq" gives me:
postqueue: warning: Mail system is down -- accessing queue directly
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
8CE558E9EC5 71 Sun Dec 3 02:45:57 username

-- 0 Kbytes in 1 Request.

[ Reply to This | # ]
aha- mailq - just what I was looking for!
Authored by: jspivack on Dec 03, '06 11:16:41PM

Thanks for the pointer to mailq. I've been looking for this command for a while.

I occasionally use a GPRS connection over bluetooth to send emails on the road using Postfix as my SMTP server, and although Eudora marked the messages as "sent", my recipients often didn't actually get the messages until the next time I reconnected to a higher-speed connection.

I figured the messages were stuck in the queue somewhere downstream of Eudora, but I couldn't figure out how to qwery the mail queue. Now I know - and it works! Next time I send an email from the road, I'll run mailq to make sure the messages have left my machine before shutting down my BT/GPRS connection.

[ Reply to This | # ]
Remove undeliverable local mail
Authored by: betabug on Dec 25, '06 04:20:25AM

After a quick mailq shows that there are still messages in the queue (or that the mail system is down, in which case mailq will report it), entering sudo postfix flush will start delivering the mails from the queue (and it starts up the mail system too if it was down).

In case you are not working as an admin user (good idea!), you can add this command to the /etc/sudoers config file (using the visudo command, never editing /etc/sudoers directly. Adding a line like this should do it fine, where "username" should be your username:

username ALL= NOPASSWD: /usr/sbin/postfix flush

[ Reply to This | # ]