Elliott has asked for the wisdom of the Perl Monks concerning the following question:

But the other 1%(ish) of my mail is not being sent. By putting my own address as well as the client's in the To: field, I have determined the fault is in sending, rather than receiving.

In the event of failure, I'd like to learn what happened. I don't want the script to stop nor any message sent back to the browser. If it didn't seem stupid, the ideal would be if it emailed me!! I suppose what I have to do is write a log file. But how? The syntax of "warn" doesn't seem to allow for that.

If it's possible, and depending on what the error turns out to be, I'd like the script to retry queuing the failed mail, at least a few times.

Anyone got any advice?

Or maybe know the right question I should be asking the webhost's tech support. After listening to their music for an hour I finally got someone who asked me what the errorlog said - and was utterly scornful when I said I wasn't writing one. I would have thought the webserver would maintain errorlogs from SendMail. Was his contempt for me justified, or was he BSing me?

Replies are listed 'Best First'.
Re: SendMail works 99% of the time
by hagus (Monk) on May 19, 2002 at 11:38 UTC
    It is a little unclear what you are after here. Where are you calling sendmail from? I assume from a CGI program hosted somewhere. If so, it depends on the type of error you're getting. If delivery failed because sendmail returned an error code, you can obviously test for that.

    If delivery is failing and being reported back with a bounce, that won't be recorded in the sendmail logs, AFAIK. What will happen is that a bounce will be generated and e-mailed to the originator of your message (using the reply-to address I guess).

    So ... you could do something like have procmail running somewhere in some special user account, invoking a script that you've written which parses bounce e-mails. Make sure the user running procmail is set as the reply-to of outgoing e-mails. Attach an X-header so you can match up replies with transmission attempts. And Bob's your father's brother.

    Seems like the best way to me - because if your hosting service's sendmail can't transmit the message, *it* will return a bounce. But what if the remote mailbox is full? Then the destination SMTP server will generate the bounce, and your hosting service's sendmail will calmly deliver that without a second glace. Sendmail doesn't parse incoming e-mails to determine whether they are bounces for something it has transmitted in the past. So your hosting providers logs of bounces (if they exist) won't contain the whole story.

    Just thinking off the top of my skull, HTH - HAND.

    --
    Ash OS durbatulk, ash OS gimbatul,
    Ash OS thrakatulk, agh burzum-ishi krimpatul!
    Uzg-Microsoft-ishi amal fauthut burguuli.

      OK, let me try for a little more clarity...

      I am calling SendMail from a cgi script. Bounces, non-receipts etc are not the issue. The issue is that the emails are not being sent every time. I assume this either because of a SendMail error or because of a failure to launch it.

      Hagus says "If delivery failed because sendmail returned an error code, you can obviously test for that." which is exactly my problem! I don't know how to log the error.

        After you call the sendmail binary, you can interrogate the $? variable for the exit code of sendmail. I am guessing that '0' means success, although the sendmail man page does not seem to list exit codes.

        After your open using pipes or system call, or whatever you use to invoke sendmail:

        # -- insert sendmail invocation here. # eg. open(SENDMAIL, "|/usr/bin/sendmail -t") $exit_value = $? >> 8; $signal_num = $? & 127; $dumped_code = $? & 128;
        (from the Cookbook)

        Anyway, how do you know that bounces are not the issue? Is the user who is sending the messages getting none at all? Maybe start off by checking the return values as above, but if sendmail is being run successfully and you are missing out on mails, I would look for bounce messages.

        --
        Ash OS durbatulk, ash OS gimbatul,
        Ash OS thrakatulk, agh burzum-ishi krimpatul!
        Uzg-Microsoft-ishi amal fauthut burguuli.

      Ash OS durbatulk, ash OS gimbatul, Ash OS thrakatulk, agh burzum-ishi krimpatul! Uzg-Microsoft-ishi amal fauthut burguuli.

      What does that mean? In case you hadn't noticed, this site is in English :)
      Update: How could I have been so foolish...

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        It's the inscription on the Ring of Power, sought after by Bill Gates, to make his conquest of Middle Earth complete.

        In the Orcish tongue of Microsoft it reads: "One OS to rull them all, one OS to find them, one OS to bring them all and in the darkness bind them. In the land of Microsoft where shadows lie."

        Let us hope I never have to utter those words here again. This is supposed to be a holy place.

        --
        Ash OS durbatulk, ash OS gimbatul,
        Ash OS thrakatulk, agh burzum-ishi krimpatul!
        Uzg-Microsoft-ishi amal fauthut burguuli.