MIME::Lite / Net::SMTP question

G

gsanuser

Hello,

We are using MIME::Lite (ver 2.117) and Net::SMTP (ver 2.19) for sending mail
from a Solaris box (perl 5.6.1).
We have a method which simplified looks like:
sub sendMail (
my $msg = build MIME::Lite(...) ;
attach $msg (...attachement ....) ;
$msg->send_by_smtp() || return 0;
return 1;
)
we are finally checking if sendMail() returns 0 or 1 in order to flag mails
correctly sent or not.

It appears that this way we are able to trap errors like "cannot connect to
host", or some STMP errors (like 500 Syntax error) but not all, i.e. error 452
(insufficient system storage) is not detected (that is, our sendMail() returns 1
as it were no problems).

Particularly errors from dataend() are not trapped. Following code from
MIME::Lite ver 2.117):

my $smtp = MIME::Lite::SMTP->new(@args) or Carp::croak("Failed to connect to
mail server: $!\n");
$smtp->mail($from) or Carp::croak("SMTP MAIL command failed:
$!\n".$smtp->message."\n");
$smtp->to(@to_all) or Carp::croak("SMTP RCPT command failed:
$!\n".$smtp->message."\n");
$smtp->data() or Carp::croak("SMTP DATA command failed:
$!\n".$smtp->message."\n");
$self->print_for_smtp($smtp);
$smtp->dataend() ;

Just asking group if this is a bug or a feature, and what is the best way to
correct this issue.

Just adding something like:

$smtp->dataend() or Carp::croak("SMTP DATAEND command failed:
$!\n".$smtp->message."\n");

or

unless (($smtp->code())== 250){Carp::croak("Mail is Not Correltly Delivered via
SMTP");}

Thanks much,
Gabriel
 
J

James Willmore

We are using MIME::Lite (ver 2.117) and Net::SMTP (ver 2.19) for
sending mail from a Solaris box (perl 5.6.1).
We have a method which simplified looks like:
sub sendMail (
my $msg = build MIME::Lite(...) ;
attach $msg (...attachement ....) ;
$msg->send_by_smtp() || return 0;
return 1;
)
we are finally checking if sendMail() returns 0 or 1 in order to
flag mails correctly sent or not.

It appears that this way we are able to trap errors like "cannot
connect to host", or some STMP errors (like 500 Syntax error) but
not all, i.e. error 452(insufficient system storage) is not detected
(that is, our sendMail() returns 1 as it were no problems).

Particularly errors from dataend() are not trapped. Following code
from MIME::Lite ver 2.117):

my $smtp = MIME::Lite::SMTP->new(@args) or Carp::croak("Failed to
connect to mail server: $!\n");
$smtp->mail($from) or Carp::croak("SMTP MAIL command failed:
$!\n".$smtp->message."\n");
$smtp->to(@to_all) or Carp::croak("SMTP RCPT command failed:
$!\n".$smtp->message."\n");
$smtp->data() or Carp::croak("SMTP DATA command failed:
$!\n".$smtp->message."\n");
$self->print_for_smtp($smtp);
$smtp->dataend() ;

Just asking group if this is a bug or a feature, and what is the
best way to correct this issue.

Just adding something like:

$smtp->dataend() or Carp::croak("SMTP DATAEND command failed:
$!\n".$smtp->message."\n");

or

unless (($smtp->code())== 250){Carp::croak("Mail is Not Correltly
Delivered via SMTP");}

I'm not 100% sure if this will work, but thinking back to a script I
wrote some time back, I seem to remember using this. I just wraped
the whole process of sending the email in an eval block. Sometimes
the errors encounter by the various email modules will not result in
the script dying, but the method used returning undef or the message
from the server.

So, you might try something like (untested):

eval{
my $smtp = MIME::Lite::SMTP->new(@args);
$smtp->mail($from);
$smtp->to(@to_all);
$smtp->data():
$self->print_for_smtp($smtp);
$smtp->dataend() ;
};

die "$@\n" if($@);

Again, I'm not 100% sure. Forgive my sin of not checking the
documentation first before posting.

Net::SMTP also has a 'Debug' setting, so you could fashion something
around that as well. At the very least, find out what the behavior of
the whole process is. I think MIME::Lite has a similar facility.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Sex is a natural bodily process, like a stroke.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top