Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sendmail error kills script 1

Status
Not open for further replies.

RottPaws

Programmer
Mar 1, 2002
478
US
I'm using MIME::Lite in a Perl script to send am email with sendmail.

Code:
$msg = MIME::Lite->new(
		From	=> $From,
		To		=> $To,
		Cc		=> $CC,
		Subject	=> $Sub,
        Bcc		=> $BCC,
		Type	=> 'multipart/mixed');

$msg->attach(
		Type	=> $BodyType,
		Data	=> $Body);
		
$msg->send('sendmail', SetSender=>1);

It works find as long as the email addresses are good, but if somebody puts a badly formated email address into the database, it causes a sendmail error which kills the script.

error closing /usr/lib/sendmail: (exit 17152)

I've tried variations of the send line (like the one below) to make the script print an error message and continue, but I haven't been able to figure out how to get the script to keep going even if the email fails.

Code:
$msg->send('sendmail', SetSender=>1) || print "Error sending message:\n";

Does anybody know how I can make it keep going when sendmail has an error?

_________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
I have not. I'm not familiar with that function.

I'm looking it up now, but if you have any examples or links you could recommend for me to learn how to use it, I'd appreciate it.

_________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
Trojan,

Thanks a bunch.[thumbsup2] That error has been driving me crazy for a long time.

I changed the send line as shown below and eval() worked perfectly.
Code:
eval{ $msg->send('sendmail', SetSender=>1); };

warn "Error sending message:\n"
    ."  --From: $From\n"
    ."  --TO: $To\n"
    ."  --BCC: $BCC\n"
    ."  --Subject: $Sub\n"
    ."  --$@\n\n"
 if $@;

_________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top