This is not a question but a deposit in the archive to let others know how to get at the error message when Net::SMTP->new() returns undef, as in ...

# Assuming 'blargh' is an unreachable host. perl -MNet::SMTP -e '$m = Net::SMTP->new( "blargh" ); $m->mail( $EVN{U +SER} )' # produces "Can't call method "mail" on an undefined value at ...".

I would have thought that if Net::SMTP->new() fails, then the error message could have been retrived via $!, more so as the module pod (version 2.31, perl 5.8.8) does not mention anything on the topic. But $! produces odd error message ...

Net::SMTP->new( 'blargh' ) or die $!; # produces "Invalid argument at -e line 1".

... try the same with $@ or without $!, more reasonable message is produced ...

Net::SMTP->new( 'blargh' ) #or die or die $@ ; # produces "Net::SMTP: Bad hostname 'blargh' at -e line 1.".

... apparently object construction is being trapped somewhere.

I see IO::Socket::INET -- only beacuse I peeked inside Net::SMTP source -- pod on new method mentions $@ but only indirectly in an example. There is no formal mention of how to get the reason for a socket connection failure.


In reply to In case of Net::SMTP->new() fauilre (for v 2.31 at least), use $@ for error message by Anonymous Monk

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.