Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to capture failure of Email::Sender

by slugger415 (Monk)
on Aug 27, 2013 at 16:33 UTC ( [id://1051162]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks, this may be a DQ (dumb question), but how do I capture a failure to connect to the SMTP server when using Email::Sender?

I've tried to capture the results in a variable:

$RES =  sendmail($email, { transport => $transport });

When it connects to $transport everything works fine, but occasionally it doesn't connect, and I see "unable to connect to SMTP server" and a bunch of trace messages. Those messages don't get put into $RES so the script can't tell if it's failed, and I can't code some appropriate behavior.

============================= unable to establish SMTP connection Trace begun at C:\strawberry\perl\site\lib\Email\Sender\Transport\SMTP +.pm line 6 Email::Sender::Transport::SMTP::_throw('Email::Sender::Transport::SMTP +=HASH(0x3 fcb9c)', 'unable to establish SMTP connection') called at C:\strawberr +y\perl\si e\lib\Email\Sender\Transport\SMTP.pm line 63 etc.... ==========================

In fact it seems that the script crashes when this happens and doesn't continue.

I've done some homework on how to catch errors but must be missing something here.

thanks!

Replies are listed 'Best First'.
Re: How to capture failure of Email::Sender
by daxim (Curate) on Aug 27, 2013 at 16:38 UTC
    That's right in the synopsis: Email::Sender - use Try::Tiny or similar to catch the exception.
      Doh! brain cramp, thank you. I understand it now.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1051162]
Approved by baxy77bax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-19 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found