Postfix mailq management question

Dear Senior Mail Admins,

I would like to seek your advise on mailq management:

root@09:30:04@mailserver:~# mailq | grep "421 too many connections" | grep "(delivery temporarily suspended" |  cut -d " " -f 5 | sort | uniq -c | sort -rn

mailq | grep "421 too many connections"
(delivery temporarily suspended: host[] refused to talk to me: 421 too many connections)
(delivery temporarily suspended: host[] refused to talk to me: 421 too many connections)


Let's say, I have a scenario: where my mailq is blown up coz of this!

I'd like to do two things:

1. I would like to delete all the mails in the mailq destined for those domains.
2. How can I temporarily move all those mails in the mailq destined for those domains to a temp folder?
3. What else can we do about it?

Thank you for your valuable piece of advise in advance.


Who is Participating?
expert1010Connect With a Mentor Commented:
1. This would do
Run this to see if it catches the mail.
mailq | tail +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" } { if ($8 ~ /^[a-z] && $9 == "") print $1 }' | tr -d '*!'

Then just add a "| postsuper -d -" at the end to delete them.
mailq | tail +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" } { if ($8 ~ /^[a-z] && $9 == "") print $1 }' | tr -d '*!'| postsuper -d -

2. -h with postsuper does the trick. You can then investigate the mails after that. They are in the hold queue and will not be handled further without your explicit intervention. raw access to the files are in your postfix path in "grep queue_directory /etc/postfix/"

mailq | tail +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" } { if ($8 ~ /^[a-z] && $9 == "") print $1 }' | tr -d '*!' | postsuper -h -

3. If you're having trouble sending to much mail to destinations you could use postfixes bulit in limiting system.  This I belive you have to experiment with. Have a look at this.
zazagorConnect With a Mentor Commented:

The solution is to simply move/delete the queue-files.
In the mail spooler folder:
mailq |grep -v '' | awk -F: '{print $1}' | awk -Ff '{print $2}' | xargs -I file rm -f dffile qffile
(instead of deleting with rm, you could move with mv)

I usually delete mail from mail queue that has no sender address:
mailq | grep '<>' | awk '{print $1}' | xargs -I file rm -f qffile dffile

Pieter JordaanSenior Systems Administrator - Web hosting and Network Security.Commented:

Are those legitimate emails?
There are many mail server spam tools that will relay mail if your server is not properly protected.

Spamassassin and postgrey work really well together to reduce spam on postfix.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

williamwlkAuthor Commented:
Thank you all for your support. Sorry for my late response as I was tied up to my operation.

expert1010: I have one issue:

mailq | tail +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" } { if ($8 ~ /^[a-z] && $9 == "") print $1 }' | tr -d '*!'

----> /^[a-z] does catch mails like "" coz it has single word but does not catch mails like "" or "" or "", which has two words or more joined with a dot or a dash.

Therefore, I'd like to change it to /
which catches starting with any single character and can be followed by any one or more characters.

Any side effect you foresee or any issues you'd like to raise if I change so?

Thanks and regards,

williamwlkAuthor Commented:
williamwlkAuthor Commented:
It is a direct hit answer! Thank you, Guys!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.