MIME::Lite / Net::SMTP question

Discussion in 'Perl Misc' started by gsanuser, Dec 10, 2003.

  1. gsanuser

    gsanuser Guest

    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
     
    gsanuser, Dec 10, 2003
    #1
    1. Advertising

  2. On 10 Dec 2003 04:11:53 -0800
    gsanuser <> wrote:
    > 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.
     
    James Willmore, Dec 10, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John B. Kim

    MIME::Lite HTML message handling

    John B. Kim, Jan 18, 2004, in forum: Perl
    Replies:
    1
    Views:
    1,711
    Joe Smith
    Jan 19, 2004
  2. Zev Steinhardt

    Perl Mime::Lite question. Help please?

    Zev Steinhardt, Aug 24, 2004, in forum: Perl
    Replies:
    1
    Views:
    760
    dan baker
    Sep 1, 2004
  3. Aaron Brady

    SQL, lite lite lite

    Aaron Brady, Dec 29, 2008, in forum: Python
    Replies:
    15
    Views:
    771
    Aaron Brady
    Jan 1, 2009
  4. Jane Humbrey
    Replies:
    5
    Views:
    284
    Jane Humbrey
    Sep 1, 2003
  5. Qnick

    MIME::Lite and smtp auth

    Qnick, Jun 28, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    96
    Qnick
    Jun 28, 2007
Loading...

Share This Page