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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Networking

From novice to tech pro — start learning today.