I am trying to add a check for the smtp server not being available. Here is the code (without the error check):
my $mailer = new Mail::Mailer('smtp', Server => $mailserver); my %headers=(); $headers{'To'} = "$recipient_email"; $headers{'From'} = "$sender_email"; $headers{'Subject'} = "$subject_email"; $mailer->open(\%headers);
If the $mailserver is not found or the smtp service is not available, then the last line fails with either "No such host is known." or "The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for."

I have tried:
$mailer->open(\%headers) || die ("cannot find smtp server");
with the same results.

I have also tried various if statements, but am not sure for what condition to check.

Any suggestions? Thanks!!


In reply to No smtp server found by ibc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.