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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |