Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

How to capture failure of Email::Sender

by slugger415 (Beadle)
on Aug 27, 2013 at 16:33 UTC ( #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!

Comment on How to capture failure of Email::Sender
Select or Download Code
Re: How to capture failure of Email::Sender
by daxim (Chaplain) 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
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? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2014-07-31 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls