<?xml version="1.0" encoding="windows-1252"?>
<node id="821468" title="getting SMTP failure codes" created="2010-02-04 18:10:08" updated="2010-02-04 18:10:08">
<type id="115">
perlquestion</type>
<author id="753905">
e5z8652</author>
<data>
<field name="doctext">
&lt;p&gt;This is hopefully a simple one, where I am just missing a clue in the docs.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Here's the script:&lt;/p&gt;

&lt;code&gt;
#test_mail.pl

use Net::SMTP;

$smtp = Net::SMTP-&gt;new(
        Host =&gt; '192.168.55.173',
        Debug =&gt; 1,
        );
$smtp -&gt; mail("root\@test-server.my.home");
@good = $smtp -&gt; recipient('good_address@my.home','bad_address@my.home',{ SkipBad =&gt; 1, Notify =&gt; ['FAILURE']});
$smtp -&gt; data();
$smtp -&gt; datasend("TO: good_address@my.home\n");
$smtp -&gt; datasend("TO: bad_address@my.home\n");
$smtp -&gt; datasend("SUBJECT: Test e-mail from root\n");
$smtp -&gt; datasend("\n");
$smtp -&gt; datasend("A test message.\n");
$smtp -&gt; dataend();

print "These addresses went: @good\n";
$smtp -&gt; quit();
&lt;/code&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;code&gt;
Net::SMTP=GLOB(0x977cdc0)&gt;&gt;&gt; MAIL FROM:&lt;root@test-server.my.home&gt;
Net::SMTP=GLOB(0x977cdc0)&lt;&lt;&lt; 250 2.1.0 Sender OK
Net::SMTP=GLOB(0x977cdc0)&gt;&gt;&gt; RCPT TO:&lt;good_address@my.home&gt; NOTIFY=FAILURE
Net::SMTP=GLOB(0x977cdc0)&lt;&lt;&lt; 250 2.1.5 Recipient OK
Net::SMTP=GLOB(0x977cdc0)&gt;&gt;&gt; RCPT TO:&lt;bad_address@my.home&gt; NOTIFY=FAILURE
Net::SMTP=GLOB(0x977cdc0)&lt;&lt;&lt; 550 5.1.1 User unknown
&lt;/code&gt;

&lt;p&gt;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.)&lt;/p&gt;

&lt;p&gt;It's got to be something simple that I am missing.  Any clues?&lt;/p&gt;</field>
</data>
</node>
