Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 31.03.2008 23:24:15 von Andrzej Filip

"Christian" wrote:
> I have a Perl mailer called that way :
>
> Matmail P=/servers/apache/sites/atmail/savemsg.pl,
> F=lsDFMA5:/|@qSPhn9, S=EnvFromL/HdrFromL,
> R=EnvToL/HdrToL,
> T=DNS/RFC822/X-Unix, U=nobody,
> A=savemsg.pl $g $u
>
> Sometimes, I get the following error :
>
> Mar 31 07:32:14 black sendmail[25866]: m2V5WDq25860: to=,
> delay=00:00:00, xdelay=00:00:00, mailer=atmail, pri=32256, dsn=5.3.0,
> stat=unknown mailer error 255
>
> I cannot find any relevant system information about a problem at the time
> this error pops up. So here is my question : is there a way to catch a
> mailer error so that the message stays in the mail queue until it gets

"man perlfunc" states that "die" when $!==0 and $?==0 causes "exits with 255".
My guess would indicate uncaught "die" in your script perl as the most
likely culprit.

I would suggest you installing $SIG{__DIE__} handler function in your
perl to:
a) "translate" exit code 255 to a value sendmail recognizes
as listed in sysexits.h file e.g.
#define EX_SOFTWARE 70 /* internal software error */
#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */

Exit code 75 would make sendmail queue message for future delivery.

b) emitting *short* problem description via STDERR (e.g. below 128 chars)

P.S.
The proper fix would be to create Sendmail::Carp CPAN module based on
CGI::Carp . Do you volunteer? ;-)

--
[pl>en: Andrew] Andrzej Adam Filip anfi@xl.wp.pl sip:896530@fwd.pulver.com
Open-Sendmail: http://open-sendmail.sourceforge.net/
The church saves sinners, but science seeks to stop their manufacture.
-- Elbert Hubbard

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 01.04.2008 15:29:38 von Christian

"Andrzej Adam Filip" a écrit dans le message de news:
cdaoifi778+Cornell@betty.fsf.hobby-site.com...
> "Christian" wrote:
>> I have a Perl mailer called that way :
>>
>> Matmail P=/servers/apache/sites/atmail/savemsg.pl,
>> F=lsDFMA5:/|@qSPhn9, S=EnvFromL/HdrFromL,
>> R=EnvToL/HdrToL,
>> T=DNS/RFC822/X-Unix, U=nobody,
>> A=savemsg.pl $g $u
>>
>> Sometimes, I get the following error :
>>
>> Mar 31 07:32:14 black sendmail[25866]: m2V5WDq25860: to=,
>> delay=00:00:00, xdelay=00:00:00, mailer=atmail, pri=32256, dsn=5.3.0,
>> stat=unknown mailer error 255
>>
>> I cannot find any relevant system information about a problem at the time
>> this error pops up. So here is my question : is there a way to catch a
>> mailer error so that the message stays in the mail queue until it gets
>
> "man perlfunc" states that "die" when $!==0 and $?==0 causes "exits with
> 255".
> My guess would indicate uncaught "die" in your script perl as the most
> likely culprit.
>
> I would suggest you installing $SIG{__DIE__} handler function in your
> perl to:
> a) "translate" exit code 255 to a value sendmail recognizes
> as listed in sysexits.h file e.g.
> #define EX_SOFTWARE 70 /* internal software error */
> #define EX_TEMPFAIL 75 /* temp failure; user is invited to
> retry */
>
> Exit code 75 would make sendmail queue message for future delivery.
>
> b) emitting *short* problem description via STDERR (e.g. below 128 chars)
>
> P.S.
> The proper fix would be to create Sendmail::Carp CPAN module based on
> CGI::Carp . Do you volunteer? ;-)
>
> --
> [pl>en: Andrew] Andrzej Adam Filip anfi@xl.wp.pl sip:896530@fwd.pulver.com
> Open-Sendmail: http://open-sendmail.sourceforge.net/
> The church saves sinners, but science seeks to stop their manufacture.
> -- Elbert Hubbard

Thank you for the hints Andrzej.

I haven't written the savemsg.pl delivery program, and I don't want to stop
Sendmail on that server when modifying it. So I see 2 options :

- write a savemsg.sh delivery prog which would be called in place of the
savemsg.pl one, and which would call the latter, test for its return code,
and exit with EX_TEMPFAIL when necessary. Fast but not very clean.
- or, in the case I want to debug the delivery prog, call a specific
delivery agent for a specific test address, that is run a dev mailer for
debug@xxxx. All other local addresses would be processed as usual by the
production mailer. Is that possible ?

Christian.

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 01.04.2008 15:49:16 von Clemens Zauner

Christian wrote:
> - write a savemsg.sh delivery prog which would be called in place of the
> savemsg.pl one, and which would call the latter, test for its return code,
> and exit with EX_TEMPFAIL when necessary. Fast but not very clean.

replace the calling of "die" ba calling "exit $retval" with the correct
return values.


--
/"\ http://czauner.onlineloop.com/
\ / ASCII RIBBON CAMPAIGN
X AGAINST HTML MAIL
/ \ AND POSTINGS

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 01.04.2008 16:05:40 von Christian

"Clemens Zauner" a écrit dans le message de news:
fstegs$1ru7$1@geiz-ist-geil.priv.at...
> Christian wrote:
>> - write a savemsg.sh delivery prog which would be called in place of the
>> savemsg.pl one, and which would call the latter, test for its return
>> code,
>> and exit with EX_TEMPFAIL when necessary. Fast but not very clean.
>
> replace the calling of "die" ba calling "exit $retval" with the correct
> return values.
>
>

The delivery prog has heaps of functions without error control. So I doubt
there's any die statement I can modify that way.

What about this new delivery prog ?

#!/bin/bash

FROM=$1
TO=$2
MAILER=/servers/apache/sites/atmail/savemsg.pl

IFS=
while read line
do
echo "$line"
done | ${MAILER} ${FROM} ${TO}

if test $? != 0; then
exit 75
fi

exit 0

It would catch any error from savemsg.pl, wouldn't it ?

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 01.04.2008 17:18:02 von Clemens Zauner

Christian wrote:
>> replace the calling of "die" ba calling "exit $retval" with the correct
>> return values.
>>
> The delivery prog has heaps of functions without error control. So I doubt
> there's any die statement I can modify that way.

OK.

> What about this new delivery prog ?

Uhhm. Long.
+++
#!/bin/sh
if /servers/apache/sites/atmail/savemsg.pl $1 $2 ; then
exit 0
else
exit 75
fi
+++

Or the like.

cu
Clemens.
--
/"\ http://czauner.onlineloop.com/
\ / ASCII RIBBON CAMPAIGN
X AGAINST HTML MAIL
/ \ AND POSTINGS

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 01.04.2008 17:34:07 von Andrzej Filip

"Christian" wrote:

> "Andrzej Adam Filip" a écrit dans le message de news:
> cdaoifi778+Cornell@betty.fsf.hobby-site.com...
>> "Christian" wrote:
>>> I have a Perl mailer called that way :
>>>
>>> Matmail P=/servers/apache/sites/atmail/savemsg.pl,
>>> F=lsDFMA5:/|@qSPhn9, S=EnvFromL/HdrFromL,
>>> R=EnvToL/HdrToL,
>>> T=DNS/RFC822/X-Unix, U=nobody,
>>> A=savemsg.pl $g $u
>>>
>>> Sometimes, I get the following error :
>>>
>>> Mar 31 07:32:14 black sendmail[25866]: m2V5WDq25860: to=,
>>> delay=00:00:00, xdelay=00:00:00, mailer=atmail, pri=32256, dsn=5.3.0,
>>> stat=unknown mailer error 255
>>>
>>> I cannot find any relevant system information about a problem at the time
>>> this error pops up. So here is my question : is there a way to catch a
>>> mailer error so that the message stays in the mail queue until it gets
>>
>> "man perlfunc" states that "die" when $!==0 and $?==0 causes "exits with
>> 255".
>> My guess would indicate uncaught "die" in your script perl as the most
>> likely culprit.
>>
>> I would suggest you installing $SIG{__DIE__} handler function in your
>> perl to:
>> a) "translate" exit code 255 to a value sendmail recognizes
>> as listed in sysexits.h file e.g.
>> #define EX_SOFTWARE 70 /* internal software error */
>> #define EX_TEMPFAIL 75 /* temp failure; user is invited to
>> retry */
>>
>> Exit code 75 would make sendmail queue message for future delivery.
>>
>> b) emitting *short* problem description via STDERR (e.g. below 128 chars)
>>
>> P.S.
>> The proper fix would be to create Sendmail::Carp CPAN module based on
>> CGI::Carp . Do you volunteer? ;-)
>
> Thank you for the hints Andrzej.
>
> I haven't written the savemsg.pl delivery program, and I don't want to stop
> Sendmail on that server when modifying it. So I see 2 options :
>
> - write a savemsg.sh delivery prog which would be called in place of the
> savemsg.pl one, and which would call the latter, test for its return code,
> and exit with EX_TEMPFAIL when necessary. Fast but not very clean.
> - or, in the case I want to debug the delivery prog, call a specific
> delivery agent for a specific test address, that is run a dev mailer for
> debug@xxxx. All other local addresses would be processed as usual by the
> production mailer. Is that possible ?

Have you considered calling the perl script from procmail script?
It will allow you to "service" case when exit code from perl script is
above value unliked by sendmail.

How do you select the mailer (the script) in sendmail.cf?
[ for some domains via mailertable, via one of relay macros in *.mc file]
Does the script use sender and recipient passed via command line?
[ $g and $u i A= ]

Test option to start with would be most likely MAILER(`procmail').
It may be selected as follows in mailertable:

example.com procmail:/etc/procmailrcs/atmail.rc

It will deliver messages to example.com via procmail using
/etc/procmailrcs/atmail.rc procmail script.

--
[pl>en: Andrew] Andrzej Adam Filip anfi@xl.wp.pl sip:896530@fwd.pulver.com
Open-Sendmail: http://open-sendmail.sourceforge.net/
If I had only known, I would have been a locksmith.
-- Albert Einstein

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 02.04.2008 09:51:02 von Christian

> Christian wrote:
>>> replace the calling of "die" ba calling "exit $retval" with the correct
>>> return values.
>>>
>> The delivery prog has heaps of functions without error control. So I
>> doubt
>> there's any die statement I can modify that way.
>
> OK.
>
>> What about this new delivery prog ?
>
> Uhhm. Long.
> +++
> #!/bin/sh
> if /servers/apache/sites/atmail/savemsg.pl $1 $2 ; then
> exit 0
> else
> exit 75
> fi
> +++
>
> Or the like.
>
> cu
> Clemens.

Thanks. I thought that stantard input wasn't passed to the child process.

Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer]

am 02.04.2008 15:28:19 von Christian

> "Christian" wrote:
>
>> "Andrzej Adam Filip" a écrit dans le message de news:
>> cdaoifi778+Cornell@betty.fsf.hobby-site.com...
>>> "Christian" wrote:
>>>> I have a Perl mailer called that way :
>>>>
>>>> Matmail P=/servers/apache/sites/atmail/savemsg.pl,
>>>> F=lsDFMA5:/|@qSPhn9, S=EnvFromL/HdrFromL,
>>>> R=EnvToL/HdrToL,
>>>> T=DNS/RFC822/X-Unix, U=nobody,
>>>> A=savemsg.pl $g $u
>>>>
>>>> Sometimes, I get the following error :
>>>>
>>>> Mar 31 07:32:14 black sendmail[25866]: m2V5WDq25860: to=,
>>>> delay=00:00:00, xdelay=00:00:00, mailer=atmail, pri=32256, dsn=5.3.0,
>>>> stat=unknown mailer error 255
>>>>
>>>> I cannot find any relevant system information about a problem at the
>>>> time
>>>> this error pops up. So here is my question : is there a way to catch a
>>>> mailer error so that the message stays in the mail queue until it gets
>>>
>>> "man perlfunc" states that "die" when $!==0 and $?==0 causes "exits with
>>> 255".
>>> My guess would indicate uncaught "die" in your script perl as the most
>>> likely culprit.
>>>
>>> I would suggest you installing $SIG{__DIE__} handler function in your
>>> perl to:
>>> a) "translate" exit code 255 to a value sendmail recognizes
>>> as listed in sysexits.h file e.g.
>>> #define EX_SOFTWARE 70 /* internal software error */
>>> #define EX_TEMPFAIL 75 /* temp failure; user is invited to
>>> retry */
>>>
>>> Exit code 75 would make sendmail queue message for future delivery.
>>>
>>> b) emitting *short* problem description via STDERR (e.g. below 128
>>> chars)
>>>
>>> P.S.
>>> The proper fix would be to create Sendmail::Carp CPAN module based on
>>> CGI::Carp . Do you volunteer? ;-)
>>
>> Thank you for the hints Andrzej.
>>
>> I haven't written the savemsg.pl delivery program, and I don't want to
>> stop
>> Sendmail on that server when modifying it. So I see 2 options :
>>
>> - write a savemsg.sh delivery prog which would be called in place of the
>> savemsg.pl one, and which would call the latter, test for its return
>> code,
>> and exit with EX_TEMPFAIL when necessary. Fast but not very clean.
>> - or, in the case I want to debug the delivery prog, call a specific
>> delivery agent for a specific test address, that is run a dev mailer for
>> debug@xxxx. All other local addresses would be processed as usual by the
>> production mailer. Is that possible ?
>
> Have you considered calling the perl script from procmail script?
> It will allow you to "service" case when exit code from perl script is
> above value unliked by sendmail.
>
> How do you select the mailer (the script) in sendmail.cf?
> [ for some domains via mailertable, via one of relay macros in *.mc file]
> Does the script use sender and recipient passed via command line?
> [ $g and $u i A= ]
>
> Test option to start with would be most likely MAILER(`procmail').
> It may be selected as follows in mailertable:
>
> example.com procmail:/etc/procmailrcs/atmail.rc
>
> It will deliver messages to example.com via procmail using
> /etc/procmailrcs/atmail.rc procmail script.
>

You're right, procmail would be a solution. And I'd be able to call a
specific prog for a specific address.

Anyway, I'm now using an intermediate Bash prog to catch errors as I said
earlier in that post.

Thank you all for the help provided.

Christian