PugSA has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on MIME::Lite aborting when it receives an error

Replies are listed 'Best First'.
Re: MIME::Lite aborting when it receives an error
by blue_cowdawg (Monsignor) on Jun 30, 2006 at 15:38 UTC
        when I send a email and the email address (RCPT) is wrong the code dies.

    More details please. What do you mean by "the code dies."

    I made an attempt at replicating what you are saying based on face value. Conisder the following code:

    #!/usr/bin/perl -w $|=1; use strict; use MIME::Lite; my @addrs=qw/ nobody@nowhere.com my_real_mail@myisp.com /; # # This is one bogus email address and one good # email address. The good address has been sanitized # for this posting. foreach my $addr(@addrs){ printf "Sending email to %s...",$addr; my $msg = MIME::Lite -> new ( From => 'my-return@isp.com', To => $addr, Subject => 'this is a test', Type=> 'TEXT', Data => 'test 1 2 3...' ); MIME::Lite->send("smtp","localhost",Port=>9925); $msg->send; printf "Message sent.\n"; }
    In my test I used one real address, and one bogus address. The loop sends to the bogus address first. It runs, no errors, no problems.

    OK... so I modified it and ran it again.

    #!/usr/bin/perl -w $|=1; use strict; use MIME::Lite; my @addrs=qw/ nobody@nowhere.com me@my-isp.net /; my $msg = MIME::Lite -> new ( From => 'me@my-isp.ne', To => join(",",@addrs), Subject => 'this is a test', Type=> 'TEXT', Data => 'test 1 2 3...' ); MIME::Lite->send("smtp","localhost",Port=>9925); $msg->send; printf "Message sent.\n";
    and this ran without problems.

    Now, in both cases the SMTP server complained to me that the address was bogus, but the mail still went to the legit address...

    So, now I'm confused. What kind of errors are you seeing?

    Before you think there is some sort of magic foo involved with the line

    MIME::Lite->send("smtp","localhost",Port=>9925);
    there isn't. This is there because my laptop does not send mail through its native sendmail instance but instead uses an SSH tunnel to send email through my main server at home. Makes configuration of my laptop easier! :-)


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      When I tried the eval{} the code was probably a bit different from what I posted, the code might have had some other error so I probably thought it was the eval as it was the first time I've used it Thank you for your time

Re: MIME::Lite aborting when it receives an error
by derby (Abbot) on Jun 30, 2006 at 14:56 UTC

    Code please ... are you using eval correctly?

    eval { $msg->send; }; if( $@ ) { # log error message }

    -derby

      Hi derby

      I've already posted the code in node 558281 that is why I referred to it

      Apologies if that is the wrong way, I used the eval{} like code below

      eval{$msg->send};

      The only difference is the semi colon after the send

      I just tested it and it worked I also did not know about $@ thank you for your time