Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

MIME::Lite error handling

by jlongino (Parson)
on Feb 28, 2003 at 21:52 UTC ( [id://239562]=perlquestion: print w/replies, xml ) Need Help??

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

I'm not sure if this is a documentation bug or if I've come across a special case. I hit a snag when trying to relay MIME::Lite send error mesasages. If I have a malformed "To: " address such as in the following snippet:
sub Send_Msg { my ($to, $from, $subject, $body) = @_; use MIME::Lite; my $msg = new MIME::Lite To => '"some name" anyone@somewhere.com', From => $from, Subject => $subject, Type => 'TEXT', Data => $body; MIME::Lite->send('smtp', "some_valid_smtp_server_name", Timeout=>6 +0); ## the following is the offending statement $msg->send || die "MIME::Lite->send failed: $!\n"; }
The correct address should be of the form '"some name" <anyone@somewhere.com>'. In the above code the program dies with an smtp message but does not display the intended die message. The statement is patterned after the MIME::Lite documentation example:
As an instance method with no arguments, sends the message by the default mechanism set up by the class method. Returns whatever the mail-handling routine returns: this should be true on success, false/exception on error:
$msg = MIME::Lite->new(From=>...); $msg->send || die "you DON'T have mail!";
However replacing the offending line with the following works correctly:
eval { $msg->send }; die "MIME::Lite->send failed: $@\n" if $@;
Does this reflect your experience and if so, is it worth notifying the module author? Thanks.

--Jim

Replies are listed 'Best First'.
Re: MIME::Lite error handling
by robartes (Priest) on Feb 28, 2003 at 22:21 UTC
    Good point. The way I read the docs, the module is behaving as it should:

    Returns whatever the mail-handling routine returns: this should be true on success, false/exception on error

    The way I read this, the send method can throw an exception, which is what is happening in your case (hence, your catching it with eval). So, it is behaving as documented.

    It could be a bit clearer though, something along the lines of ... returns false or throws an exception on error..

    Update: closed italics tag. Thanks AlexL.

    CU
    Robartes-

Re: MIME::Lite error handling
by Anonymous Monk on Oct 12, 2011 at 05:54 UTC
    Thanks a lot, even almost a decade later you tip is saving life of many people :)
      i tried to this code in Utilities.pm then call this from other script but it didin't capture error each time it is succesful even if am not providing the To or cc mail recieptents.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://239562]
Front-paged by traveler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-19 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found