S
Simon Andrews
I have a strange strange problem setting up some CGI scripts on a new
webserver which seem to boil down to the way that different modules
connect to an SMTP server.
I have two scripts which send email. One uses Mail::Sendmail and the
other uses MIME::Lite (which itself uses Net::SMTP for the connection).
The Mail::Sendmail script works fine, both from a commandline and when
run as a CGI script. The MIME::Lite script works fine from the command
line, but fails when run as a CGI.
Both scripts are pointing to the same SMTP server and both work fine
when run from our old webserver.
I am at a complete loss to debug this problem. The Net::SMTP connect
fails during the new() statement, and I don't get any debugging output.
Since both scripts are just opening a socket on port 25 I can't see what
could be set in the webserver configuration which would stop one from
working.
The symptoms suggest this must be a webserver configuration problem but
I don't know how to get any more details about the failed connection so
I can try to track down exactly what's failing.
I've included the test scripts I used. The first one fails, but the
second one works. Beyond the test in the die statement I get nothing in
the log file when the first script fails.
###############################################
#!perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use NET::SMTP;
$NET::SMTP:
ebug = 1;
open (STDERR,'>','E:\Errors\smtp_log.txt') or die "Can't write to
logfile: $!";
my $q = new CGI;
print $q -> header();
print $q -> start_html();
print "<pre>";
print "Connecting to smtp server\n";
my $smtp = Net::SMTP->new('our.mail.server',Debug => 1) or die "Can't
connect to mail server";
$smtp -> mail('(e-mail address removed)');
$smtp -> to('(e-mail address removed)');
$smtp -> data();
$smtp -> datasend("To: simon.andrews\@bbsrc.ac.uk\n\n");
$smtp -> datasend("Test message\n\n");
$smtp -> dataend();
$smtp -> quit();
print "Finished connecting\n";
print "</pre>";
print $q -> end_html();
##################################################
#!perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;
open (STDERR,'>','E:\Errors\sendmail_log.txt') or die "Can't write to
logfile: $!";
my $q = new CGI;
print $q -> header();
print $q -> start_html();
print "<pre>";
print "Connecting to smpt server\n";
$Mail::Sendmail::mailcfg{debug} = 6;
my %mail = (To => '(e-mail address removed)',
From => '(e-mail address removed)',
Message => 'This is a test',
smtp => 'our.mail.server',);
sendmail(%mail) or die "Can't send mail $Mail::Sendmail::error";
print "Log says:\n";
print $Mail::Sendmail::log;
print "Finished connecting\n";
print "</pre>";
print $q -> end_html();
webserver which seem to boil down to the way that different modules
connect to an SMTP server.
I have two scripts which send email. One uses Mail::Sendmail and the
other uses MIME::Lite (which itself uses Net::SMTP for the connection).
The Mail::Sendmail script works fine, both from a commandline and when
run as a CGI script. The MIME::Lite script works fine from the command
line, but fails when run as a CGI.
Both scripts are pointing to the same SMTP server and both work fine
when run from our old webserver.
I am at a complete loss to debug this problem. The Net::SMTP connect
fails during the new() statement, and I don't get any debugging output.
Since both scripts are just opening a socket on port 25 I can't see what
could be set in the webserver configuration which would stop one from
working.
The symptoms suggest this must be a webserver configuration problem but
I don't know how to get any more details about the failed connection so
I can try to track down exactly what's failing.
I've included the test scripts I used. The first one fails, but the
second one works. Beyond the test in the die statement I get nothing in
the log file when the first script fails.
###############################################
#!perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use NET::SMTP;
$NET::SMTP:
open (STDERR,'>','E:\Errors\smtp_log.txt') or die "Can't write to
logfile: $!";
my $q = new CGI;
print $q -> header();
print $q -> start_html();
print "<pre>";
print "Connecting to smtp server\n";
my $smtp = Net::SMTP->new('our.mail.server',Debug => 1) or die "Can't
connect to mail server";
$smtp -> mail('(e-mail address removed)');
$smtp -> to('(e-mail address removed)');
$smtp -> data();
$smtp -> datasend("To: simon.andrews\@bbsrc.ac.uk\n\n");
$smtp -> datasend("Test message\n\n");
$smtp -> dataend();
$smtp -> quit();
print "Finished connecting\n";
print "</pre>";
print $q -> end_html();
##################################################
#!perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;
open (STDERR,'>','E:\Errors\sendmail_log.txt') or die "Can't write to
logfile: $!";
my $q = new CGI;
print $q -> header();
print $q -> start_html();
print "<pre>";
print "Connecting to smpt server\n";
$Mail::Sendmail::mailcfg{debug} = 6;
my %mail = (To => '(e-mail address removed)',
From => '(e-mail address removed)',
Message => 'This is a test',
smtp => 'our.mail.server',);
sendmail(%mail) or die "Can't send mail $Mail::Sendmail::error";
print "Log says:\n";
print $Mail::Sendmail::log;
print "Finished connecting\n";
print "</pre>";
print $q -> end_html();