Smtry to manage mail queue

If you have a program or script that you'd like to give away or sell, this is the place to do it. All offers should include contact info.

Moderators: BBear, theunknownhost, flaguy

Post Reply
User avatar
khimaira2
Nothing better to do.
Posts: 202
Joined: Mon Sep 20, 2004 12:19 pm
Location: Location: Location:

Smtry to manage mail queue

Post by khimaira2 » Sat Feb 10, 2007 7:25 pm

Let's face it, despite your best efforts, there's almost always going to be a few messages backed up in the mail queue. Arf and others have given us several great tools, but I don't think I ever seen this one mentioned. I've had it for so long I don't remember how much is original and how much I've modified, but it's basically just an easy to use front end to some sendmail command line options used to process the mail queue.

Usage: smtry [ -a | -q queueid | -s sender | -r recipient ]
-a Try ALL queued Sendmail jobs
-q queueid Try job queued for specified queueid
-s sender Try jobs queued for specified sender
-r recipient Try jobs queued for specified recipient

Note: A partial specification of queueid, recipient, or sender is effective
as a substring and the specification is not case-sensitive. Wildcards and
regular expressions are not allowed.

So for example, to process all those messages backed up to someone@odds.com,you could just type: smtry -r odd

I hope you find it helpful.

Code: Select all

#!/bin/sh
# @(#) smtry - Try Sendmail jobs by queueid, recipient, sender, or all
# Requires Sendmail

$DBG_SH     # Debugging directive
Flag=""     # Initially, no user-specified flag

# Function to handle usage errors:
usage_exit() {
echo "$*" >&2
cat << !EOF! >&2
Usage: `basename $0` [ -a | -q queueid | -s sender | -r recipient ]
    -a             Try ALL queued Sendmail jobs
    -q queueid     Try job queued for specified queueid
    -s sender      Try jobs queued for specified sender
    -r recipient   Try jobs queued for specified recipient

Note: A partial specification of queueid, recipient, or sender is effective
as a substring and the specification is not case-sensitive. Wildcards and
regular expressions are not allowed.
!EOF!
    exit 1
}

# Check initial command-line argument count:
case $# in
    1|2)    ;;  # okay, if one or two
    *)      usage_exit "Invalid invocation argument count" ;;
esac

# Process command-line options:
    while [ $# -gt 0 ]; do
        case $1 in
            -a) [ "$Flag" ] && usage_exit "Only one option allowed"
                Flag=X ; /usr/sbin/sendmail -v -q ; shift ;;
            -q) [ "$Flag" ] && usage_exit "Only one option allowed"
                [ "$2" ] || usage_exit "-q option requires an argument"
                Flag=X ; /usr/sbin/sendmail -v -qI${2} ; shift ; shift ;;
            -r) [ "$Flag" ] && usage_exit "Only one option allowed"
                [ "$2" ] || usage_exit "-r option requires an argument"
                Flag=X ; /usr/sbin/sendmail -v -qR${2} ; shift ; shift ;;
            -s) [ "$Flag" ] && usage_exit "Only one option allowed"
                [ "$2" ] || usage_exit "-s option requires an argument"
                Flag=X ; /usr/sbin/sendmail -v -qS${2} ; shift ; shift ;;
            --) shift ; break ;;    # end of option list
            -*) usage_exit "Unrecognized option \"$1\"" ;;
            *)  break ;;
        esac
    done
Outside the box member

User avatar
Arf
Official Test Penquin
Posts: 9103
Joined: Tue Apr 09, 2002 12:00 am
Location: IDAHO, USA
Contact:

Post by Arf » Sun Feb 11, 2007 5:00 pm

This is a handy tool to push out emails stuck in the queue. My experience is that the server will continue to retry on it's own. Under what circumstances do you use this command?

What are the chances that the emails stuck in queue are simply never going to get out?

User avatar
khimaira2
Nothing better to do.
Posts: 202
Joined: Mon Sep 20, 2004 12:19 pm
Location: Location: Location:

Correct

Post by khimaira2 » Sun Feb 11, 2007 5:59 pm

You are absolutely correct. Sendmail will continue to attempt delivery up to the typical timeout of 5 days. However it does use a logarithmic regression, which simply means the longer the failure continues, the less frequently it tries. So scenarios where you might use this command:

1) You think a server that was down, busy, or for some other reason unavailable is now back up and you want to expedite the flushing of backlogged messages.
2) It's hard to believe, but I've seen incorrrect DNS lookups for MX servers. Once you straighten that out you may enjoy the satisfaction of seeing the mail on its way.
3) Not that I have this problem anymore, but I have seen servers that were rejecting connections, yield to my persistent smtry's.
4) Sure there is a brief one-liner in the mailq output that explains the reason for non-delivery. But I'm both skeptical and non-accepting of rejection. I like to smtry and see the full story of what's happening.
5) For geeks, sometimes it's just fun!

And oh yeah, there are some stuck messages that are never going to go. Then I'm the stuck with the quandary whether to delete the message and know the sender (or mailinglist) will never know what happened, or, wait the 5 days for sendmail to clean it up nicely.

Incidentally, I do use the recommended qtool.pl to delete messages, but I would be interested to know if there is a way to automatically inform the sender of the rejection.
Outside the box member

User avatar
Arf
Official Test Penquin
Posts: 9103
Joined: Tue Apr 09, 2002 12:00 am
Location: IDAHO, USA
Contact:

Post by Arf » Mon Feb 12, 2007 6:46 pm

"logarithmic regression" Wow. cool phrase.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest