Check mail queue

We use Redhat server , we always use mailq to check any pending mail in mailq , when run the command mailq , it shows all existing pending mail would advise how to write a script to show the pending mails which are older than 24 hours , ( if possible , then send this pending mail info to admin@mydomain.com )? very thanks

I suspect that if you have pending mail, then generating a report to try to e-mail you a warning will also get stuck.

If your internet connection at home is not working, how do you e-mail the company/log a fault on their web-site to let them know? You have to use another method, e.g. phone, use an alternate provider next door etc.

What alternate notification have you considered?

Robin

thanks reply ,

the email will send to my mobile phone , and my email system is very stable , it nearly 99.99% availability .

If outgoing e-mail is stuck on your server, how will the notification get out to your mobile?

Consider a door bolted from the other side. How will you get a message out to ask someone to open the door?

I feel you are missing my point here.

Robin

thanks reply ,

would you please ignore the probability of server failure .

thanks

You are completely missing the point!

If mail is stuck on your server, you can't send mail to anyone saying that mail is stuck because the mail message saying the mail is stuck will also be stuck.

The entire point of this thread is that your mail server is failing to deliver mail messages. If we ignore that there is a possible server failure, there is no need to send a message saying there has been a failure since you want to ignore what has happened.

If we don't ignore that your mail server has failed, you have to use some mechanism other than mail to deliver that notification.

As an example, if your car runs out of gas, you can't drive that car to a gas station to get more gas. You can call AAA to deliver gas to you; you can walk to a gas station, buy a gas can, fill the can with gas, walk back to your car, and put the gas you bought into you car; you can abandon your car and start using a bicycle to get around; or you can get around several other ways.

But, until you fix your mail server failure, you can't send mail to anyone saying that you have a mail server failure.

thanks suggestions

mails stopped in the mailq usually because the particular mail domain error or mail relay problem , it do not cause the mail completely can't send out .
therefore , I think use script to check the mailq status is reasonable.

Do you have super-user access? If so, the mail will be stored in files according to your system configuration (you don't tell us the distribution) but it's likely to be under /var somewhere. Perhaps one of these:-

  • /var/mail/queue
  • /var/spool/mail
  • /var/spool/mqueue

..... or something similar. Have a look at the manual page for sendmail to see if that gives you some more clues. You can then check to see if there are files in there at all (might see something whilst it is processing) or files over 24-hours old. You can use the find command for that quite nicely.

Does that help you? I'm still not convinced your plan is a good one though. What we do is to have a heartbeat e-mail. Essentially we send a note on a regular basis and someone/something alerts if it hasn't arrived.

Another alternate is you could drive the query from another server. You could write error checking there to alert you if:-

  • You can't connect
  • You can't run the job
  • There is pending e-mail

If you can perform the error checking on this other server, then you could hope that it would be able to notify you, although it still depends on the common infrastructure not being the point of failure.

Robin

1 Like

thanks reply ,

it helps , I know the command "mailq" can show all pending mail , what I hope to do is extract such raw data into a alert mail .

thanks

So, if mail is stuck, you still want to send an alert by e-mail.......... :confused:

Unless the manual page for your mailq command gives you a flag to get the mail submission date/time, then you would be best looking in the directories I have suggested or similar to see the file date/times if any exist.

You really do need to think of another route for your alert that won't get stuck in exactly the same way as what you are trying to check up on.

If you can't think of one, then perhaps a regular e-mail that gets reported on if it doesn't arrive. Do you have a 24-hour operation that has people on site round the clock? If they have a team mailbox, then that's a good place to send it and have a check at whatever intervals that it has been received. If not, then they (people) can alert as required.

Robin