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

Hi All, I need to send mass mail to users about disk quota, the problem is when ever the SMTP cant find the user name email's address it dies and never complete the task what i want it to do is to trap the error and save it to some var and save it to a log file something like:
$msg->send() || print FILE $str;
!! and to keep sending !! to other users not die !! any advice?
$to = "$to\@somemail.com"; $from = "$from\@somemail.com"; $subject = "Email Sent via Perl"; $message = "This email was sent using Perl."; email($to, $from, $subject, $message,); sub email { local ($to, $from, $subject, $message) = @_; $msg = MIME::Lite->new( From => $from, To => $to, Subject => $subject, Data => $message ); MIME::Lite->send('smtp', 'some.smtp.smtp',Debug=>1); $msg->send(); }

Replies are listed 'Best First'.
Re: Send mail error
by gmargo (Hermit) on Nov 22, 2009 at 16:52 UTC

    What error are you getting? Have you tried wrapping the $msg->send() inside an eval?

      Indeed, the internals to MIME::Lite will die if the RECIPIENT command fails when sending via SMTP, such as if the e-mail address is invalid (see the latest source in the send_by_smtp method). The easiest way around this is to wrap the send call inside an eval.

      Barring that, you'll have to use something else other than MIME::Lite's send, such as utilizing another module.