Having a problem where the connections to an smtp server doesn't seam to close correctly on Windows NT. I've tried two separate mailing modules (MIME::Lite and Mail::Sender). Neither will send a second time without re-starting Apache. The Lite module uses the Net::smtp module and the Sender directly uses a Socket (not IO::Socket). Additional details are listed further down. My general question is: Are there problems with "PERL" Sockets on mod_perl/NT? Since a nearly identical test program works from the PERL.exe command line it seams as if mod_perl is trying to keep the port open or something.
 
Also, there are some directories that came with the Apache/mod_perl binary distribution that have Socket.pm files in them. These directories are perl\lib\MSWin32-x86 and perl\lib\MSWin32-x86\IO. Should they have been copied over the other files in the perl directory tree? Or, put in the startup.cgi(listing is at bottom)? The distribution came with little docs and it was my first mod_perl setup.
 
Any infomation would be greatly appreciated. 
 
 
Chuck Goehring
[EMAIL PROTECTED]
 
Below are more details of the problem I've been having.
----------------------------------------------
Details:
I'm using MIME::Lite to let users email files to other users as part of a document management system. The MIME::Lite package inherits from Net::SMTP (@ISA = qw(Net::SMTP);) and adds the capability to add attachments to the email.
It works fine the first time but gives an error the second time. If I run it external to the site via the perl.exe command line (with use CGI lines removed), it works flawlessly every time. Once the error starts, even leaving it overnight doesn't allow it to work. It acts as though the socket doesn't get closed and can't be reused. Below are the pertinant scripts.
 
----------------------------------------------
MIME::Lite sub to send via smtp:
 
sub send_by_smtp {
 
my ($self, @args) = @_;
# We need the "From:" and "To:" headers to pass to the SMTP mailer:
my $hdr = $self->fields();
my $from = $self->get('From');
my @to = $self->get('To');
# Create SMTP client:
require Net::SMTP;
my $smtp = MIME::Lite::SMTP->new(@args)
or croak "Failed to connect to mail server: $!";
$smtp->mail($from)
or croak "SMTP MAIL command failed: $!";
$smtp->to(@to)
or croak "SMTP RCPT command failed: $!";
$smtp->data()
or croak "SMTP DATA command failed: $!";
# MIME::Lite can print() to anything with a print() method:
$self->print($smtp);
$smtp->dataend();
$smtp->quit;
1;
}
 
----------------------------------------------
The Error from MIME::Lite:
[Sun May 14 16:20:10 2000] -e: Failed to connect to mail server: Bad file descriptor at c:/apache/cgi-perl/test_sa_mime.cgi line 38 (Line 38 contains $SMTPRetVal = $msg->send_by_smtp($SMTPhost, Timeout => 40);
----------------------------------------------
Configuration:
Windows NT service pack 4
Apache 1.3.3 with mod_perl 1.16 binary from www.apache.org
cgi.pm 2.42
Socket.pm 1.6
Mime::Lite (Lite.pm,v 1.134 1999/04/17 04:59:03 eryq Exp)
----------------------------------------------
The test script:
$| = 1;
###### LIBS ##########
use strict;
use CGI qw/:standard :html3/;
use CGI::Carp qw(fatalsToBrowser); # carpout ====> # for Apache
use Apache::DBI();
use Apache qw(exit);
 
myRun();
Apache::exit;
 
 
 
##########
sub myRun {
 
 
  print header();
  print start_html(-title => 'Mime test');
  print '<h4>This one should work.</h4>';
 
  use lib 'c:\perl\lib\site\mime';
  use MIME::Lite;
  my ($OpStatus, $recip, $SMTPRetVal);
  $recip = '[EMAIL PROTECTED]';
  print '<br>TestMime: Starting test of Mime';
  my $SMTPhost = 'rcisd.com';
  print '<br>TestMime: Host = ' . $SMTPhost;
  my $messbod = 'Testing mime module';
  my $Subj = 'TestMime';
  my $msg;
  $msg = '';
  $msg = build MIME::Lite From => '[EMAIL PROTECTED]',
    To => $recip, Subject => $Subj,
    Type => 'TEXT', Data => $messbod;
    print "<br>TestMime: Recipient = $recip.";
  eval{
    $SMTPRetVal = $msg->send_by_smtp($SMTPhost, Timeout => 40);
  };
  if($@) {
    print "<br>TestMime: Status after mail via $SMTPhost was: <br>$@";
  }
  if($SMTPRetVal) {
  } else {
    print q(<br><font color='#FF0000'>TestMime: Send Failed for ) . $recip . '</font>';
  }
  undef $msg;
  print '<br>Done';
  print end_html();
  return;
}
----------------------------------------------
Apache startup.cgi:
use strict;
use Apache ();
use Apache::Registry;
use Apache::DBI();
use Carp();
use CGI qw(-compile :all);
 
 
#use lib map { "$ENV{PWD}/blib/$_" } qw(arch lib);
#use lib map { Apache->server_root_relative("blib/$_") } qw(arch lib);
1;
__END__
 

Reply via email to