Jason Vincent wrote: > Hello, > > I am sending html formatted email using MIME::Lite. I am > looking for a way of providing backup smtp mail servers to the send > function in case the specified smtp server is not available. However, > if the smtp server supplied is not valid or not available, the program > dies. Is there no way to retrieve a success/failure from the send > function and upon failure, offer up another smtp server choice? > > something like... > > unless (MIME::Lite->send('smtp', $smtpServer, Timeout=>60)) { > MIME::Lite->send('smtp', $smtpServer2, Timeout=>60); > } > $msg->send;
The easiest thing to try is using an eval: eval { $msg->send; }; print "[EMAIL PROTECTED]@\n" if $@; # $@ should be set if it died # or use a try catch mechanism : sub try (&@) { my ($try, $catch) = @_; eval { &$try }; if ($@) { local $_ = $@; &$catch; } } sub catch (&) { $_[0] } try { $msg->send; } catch { print "Caught [EMAIL PROTECTED]"; }; -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Unix-Users mailing list Perl-Unix-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs