According to the docs for Net::SMTP,

Unless otherwise stated all methods return either a *true* or *false* value, with *true* meaning that the operation was a success. When a method states that it returns a value, failure will be returned as *undef* or an empty list.

So, you should simply check the return value of $smtp->dataend().

my $smtp = Net::SMTP->new('smtp.orcon.net.nz', Timeout => 30, Debug => 0, # Prevent debug info to STDO +UT ); $smtp->mail('no@one.com'); # Don't need to escape @ in single-quotes $smtp->to('xxx@yyy.com'); # Fixed typo; you forgot opening quote. :) $smtp->data(); $smtp->datasend("To: xxx\@yyy.com\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); my $res = $smtp->dataend(); $smtp->quit; print "Operation was ", $res ? '' : 'un', "successful.\n";

Also, you might want to just pass the message to $smtp->data(), as it looks cleaner (personal opinion :)

use Net::SMTP; my $smtp = Net::SMTP->new('smtp.example.com', Timeout => 30, Debug => 0, # Prevent debug info to STDO +UT ); $smtp->mail('someone@example.com'); $smtp->to('someone@example.com'); my $ret = $smtp->data(<<'EOM'); From: someone@example.com To: someone@example.com Subject: Test Message A simple test message. EOM print "Operation was ", $ret ? '' : 'un', "successfull.\n"; print "(Got response: ", $smtp->message(), ")\n"; $smtp->quit;

bbfu
Black flowers blossum
Fearless on my breath


In reply to (bbfu) (how to tell if send was successful) Re: Net:SMTP Printing to STDOUT by bbfu
in thread Net:SMTP Printing to STDOUT by Gerard

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.