Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

How to capture failure of Email::Sender

by slugger415 (Scribe)
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 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\ 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.


Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1051162]
Approved by baxy77bax
[choroba]: Trainspotting without OV is just a half of the movie!
LanX just single handedly stopped Brexit!
[Happy-the-monk]: LanX; you did?
[Discipulus]: ah! plastering thanks..

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2018-02-19 10:55 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (262 votes). Check out past polls.