Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This is hopefully a simple one, where I am just missing a clue in the docs.

What I want is a simple script that tells me if an e-mail sent with Net::SMTP succeeds, or if it does not, why it does not.

In the example below I have a short script that sends mail, and tells me which addresses were successful. What I would like is to also list which ones failed -- hopefully with a failure code as well.

Here's the script: use Net::SMTP; $smtp = Net::SMTP->new( Host => '', Debug => 1, ); $smtp -> mail("root\"); @good = $smtp -> recipient('good_address@my.home','bad_address@my.home +',{ SkipBad => 1, Notify => ['FAILURE']}); $smtp -> data(); $smtp -> datasend("TO: good_address@my.home\n"); $smtp -> datasend("TO: bad_address@my.home\n"); $smtp -> datasend("SUBJECT: Test e-mail from root\n"); $smtp -> datasend("\n"); $smtp -> datasend("A test message.\n"); $smtp -> dataend(); print "These addresses went: @good\n"; $smtp -> quit();

When I run this the print statement does print out good_address@my.home as I expect. And I can see how the addresses succeed or fail with the debug output:

Net::SMTP=GLOB(0x977cdc0)>>> MAIL FROM:<> Net::SMTP=GLOB(0x977cdc0)<<< 250 2.1.0 Sender OK Net::SMTP=GLOB(0x977cdc0)>>> RCPT TO:<good_address@my.home> NOTIFY=FAI +LURE Net::SMTP=GLOB(0x977cdc0)<<< 250 2.1.5 Recipient OK Net::SMTP=GLOB(0x977cdc0)>>> RCPT TO:<bad_address@my.home> NOTIFY=FAIL +URE Net::SMTP=GLOB(0x977cdc0)<<< 550 5.1.1 User unknown

What I would like is to get bad_address and the 550 user unknown error into a form where I can print it. (This will eventually end up in a cgi script.)

It's got to be something simple that I am missing. Any clues?

In reply to getting SMTP failure codes by e5z8652

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (7)
    As of 2018-03-22 02:57 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (272 votes). Check out past polls.