in reply to Mail::Sender error

Hmmm ... not sure but why don't you check for errors

$sender->Open( ... ) or die "Error: $Mail::Sender::Error\n";

I always wrap stuff like this (Mail::Mailer) in one sub (or local package) that dies on error and then I just eval the call.

sub mymail { my( $to, $text ) = @_; eval { Local::Mail::send( $to, $text ); }; warn "Errors: $@\n" if $@; }

and then in the Local::Mail::send method would just be a wrapper for Mail::Sender that dies on any error.

-derby

updateI just perused the source of Mail::Sender and noticed that an exit value of 40 is SERVNOTAVAIL (and it closes the socket which explains the rest of your error messages). Moral: check for errors and act appropriately.

Replies are listed 'Best First'.
Re: Re: Mail::Sender error
by neilwatson (Priest) on Aug 15, 2002 at 19:07 UTC
    updateI just perused the source of Mail::Sender and noticed that an exit value of 40 is SERVNOTAVAIL (and it closes the socket which explains the rest of your error messages). Moral: check for errors and act appropriately.

    I'm sorry, can you explain that?

    Neil Watson
    watson-wilson.ca

      Sure, in a nutshell, there's an issue with the mail server and its not available (SERVNOTAVAIL). Mail::Sender is noticing the unavailabilty, setting an error code, and then closing the socket to the server.

      At its heart Mail::Sender uses SMTP. The protocol is quite simplistic (hence the S) and returns a code with each reply.

      The author has decided to reduce the myriad of 4xx and 5xx STMP error replies to a single SERVNOTAVAIL message. In addition, if for some reason he cannot read from the socket (lost connection, crashed machine), he flags that as SERVNOTAVAIL too.

      This is one of the disadvantages of using SMTP directly as opposed to an MTA (mail transfer agent) like sendmail. If you drop an email into an MTA, it may try to send the email several times for you. When using STMP directly, you have to decide what to do (drop them to the floor, queue them up for another go-round, etc).

      -derby

        Found it. Turns out an earlier regex was not capturing the to email address properly. Without the correct address the smtp server would baulk.

        Thanks for your help

        Neil Watson
        watson-wilson.ca

      Mail::Sender is generating an error message because it could not connect to the server. Because you are not checking for errors, you would never know that and your code continues anyway. A quick perusal of the Mail::Sender doc suggests some error checking techniques. Something to the effect of:
      $sender->Open({ smtp =>'mail', to =>"$from", from =>"$ticketad", fake_from =>"$ticketad", subject =>"Help Desk Submission", headers => "Errors-To: postmaster\@mydomain.com"}); die "Error: $Mail::Sender::Error\n" unless ref $sender;
      -- vek --