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

I upgraded to Perl 5.8.0 then installed a new Mail::Sender v 0.8.06. This code was working but now it is not:

#!/usr/bin/perl -w use strict; use warnings; use Mail::Sender; my $smtp = "mail"; my $from = "nwatson\@mydomain.com"; my $ticketad = "fakefrom\@mydomain.com"; my $sender = new Mail::Sender; $sender->Open({ smtp =>$smtp, to =>$from, from =>$ticketad, #fake_from =>$ticketad, subject =>"Reply from mydomain for TEST", headers => "Errors-To: postmaster\@mydomain.com"}); die "Error: $Mail::Sender::Error\n" unless ref $sender; $sender->Body; $sender->SendLineEnc(<<"*END*"); Your support request has been received by mydomain Staff Support and w +ill be tracked as specified in the subject line of this email. When contacting us regarding this issue: 1) Please use the above subject line, or, ensure the full ticket ID, e +.g. is included in the subject line, for any emails regarding this pa +rticular issue. 2) All email should be directed to vgsupport\@mydomain.com for trackin +g purposes. -------------------- -------------------- Thank you, mydomain Staff Support *END* $sender->Close or die "Failed to send the message: $sender->{error_msg +}, $Mail::Sender::Error\n";

The script is returning this error: Failed to send the message: Connection not established, Connection not established

On the SMTP side this is in syslog:

collect: premature EOM: Error 0 collect: unexpected close on connection from endor.mydomain.com,

Anyone have any idea?

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: New Mail::Sender not working?
by phydeauxarff (Priest) on Mar 29, 2003 at 00:23 UTC
    Mail::Sender has a debug parameter where all conversations with the server are logged to a file.

    You might try adding

     debug=>"debug.txt"
    to your open call to see if anything is being captured.

    Admitedly, I have never used Mail::Sender before, but have used Mime::Lite with smashing success. You might try that as an alternative if things get really frustrating.

      Tried the debug option:

      >> 220 mydomain.com ESMTP Sendmail 8.11.6+Sun/8.9.3; Fri, 28 Mar 2003 +19:47:14 -0500 (EST) << ehlo localhost.localdomain >> 250-mydomain.com Hello endor.mydomain.com [205.150.90.55], pleased +to meet you >> 250-ENHANCEDSTATUSCODES >> 250-EXPN >> 250-VERB >> 250-8BITMIME >> 250-SIZE 10000000 >> 250-ONEX >> 250-ETRN >> 250-XUSR >> 250 HELP << mail from: <fakefrom@mydomain.com> >> 250 2.1.0 <fakefrom@mydomain.com>... Sender ok << rcpt to: <nwatson@mydomain.com> >> 250 2.1.5 <nwatson@mydomain.com>... Recipient ok << data >> 354 Enter mail, end with "." on a line by itself << To: nwatson@mydomain.com << From: fakefrom@mydomain.com << Subject: Reply from mydomain for TEST << Date: Fri, 28 Mar 2003 19:19:19 -0500 << X-Mailer: Perl script "test.pl" << using Mail::Sender 0.8.06 by Jenda Krynicky, Czechlands << running on localhost.localdomain (127.0.0.1) << under account "nwatson" << Message-ID: <20030329_001919_090188.fakefrom@mydomain.com> << Errors-To: postmaster@mydomain.com

      So I would guess that the Body, SendLineEnc, or Close is causing the problem? Could this be bug or, was I just lucky before?

      Neil Watson
      watson-wilson.ca

Re: New Mail::Sender not working?
by bbfu (Curate) on Mar 29, 2003 at 08:14 UTC

    Unless you're doing something more complicated than the code you posted, you should probably use the MailMsg method instead of manually calling Body and SendLineEnc. Here is your posted code using MailMsg:

    #!/usr/bin/perl -w use strict; use warnings; use Mail::Sender; my $smtp = "mail"; my $from = "nwatson\@mydomain.com"; my $ticketad = "fakefrom\@mydomain.com"; my $sender = new Mail::Sender; die "Error: $Mail::Sender::Error\n" unless ref $sender; my $result = $sender->MailMsg( smtp => $smtp, to => $from, from => $ticketad, #fake_from => $ticketad, subject => "Reply from mydomain for TEST", headers => "Errors-To: postmaster\@mydomain.com"}); msg => <<'*END*', Your support request has been received by mydomain Staff Support and will be tracked as specified in the subject line of this email. When contacting us regarding this issue: 1) Please use the above subject line, or, ensure the full ticket ID, e.g. is included in the subject line, for any emails regarding this particular issue. 2) All email should be directed to vgsupport\@mydomain.com for tracking purposes. -------------------- -------------------- Thank you, mydomain Staff Support *END* ); die "Error: $Mail::Sender::Error\n" unless ref $result; ref($sender->Close()) or die "Failed to send the message: $Mail::Sender::Error\n";

    As to why your code isn't working, I'm guessing (and this is only a guess), that someone, somewhere (server or Mail::Sender) is getting confused by the mix of local newlines in the message body and the network newline at the end. Either that, or the socket is getting closed in some strange way that is not apparent from this code. *shrug*

    bbfu
    Black flowers blossom
    Fearless on my breath

Re: New Mail::Sender not working?
by Jenda (Abbot) on Mar 29, 2003 at 18:51 UTC

    You are supposed to use ->Body(), ->Part() or ->Attach() only if you used ->OpenMultipart() to open the message. The ->Open() starts just a plain old simple email message without any MIME parts or attachments.

    I guess I should throw/report an error if you use any of these in a single-part message.

    Update: Seems I already do that. But of course since you did not test the return value of $sender->Body() ...
    The reason why this did work before and doesn't work now is that now I close the connection if there is an error like this.

    BTW: Take a look at the new on_errors option of the constructor. It may be easier to handle the errors if you ask Mail::Sender to throw exceptions which you may then catch in an outer block/subroutine.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Re: New Mail::Sender not working?
by neilwatson (Priest) on Mar 29, 2003 at 12:05 UTC
    Seems that removing the line $sender->Body; solved the problem.

    Neil Watson
    watson-wilson.ca