SMPT Connection Errors

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::Debug = 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();
 
S

Simon Andrews

Simon said:
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.

As always, having wrestled with this all morning we find the answer
within 5 mins of posting to the newsgroups!

It turns out that the reason it was failing was that the webserver user
didn't have read access to c:\Windows\System32\drivers\etc\protocol
which is just a list of protocols and port numbers. I don't know
exactly where this access attempt comes from (IO::Socket?), but this
causes the failure even if we explicity set a port number in the
Net::SMTP connect statement.

Hopefully this will be useful for someone else in the future.

Cheers

Simon.
 
T

Tad McClellan

Simon Andrews said:
other uses MIME::Lite (which itself uses Net::SMTP for the connection). ^^^

use NET::SMTP;

$NET::SMTP::Debug = 1;
^^^


s/NET/Net/g; # ??
 
S

Simon Andrews

Tad said:
^^^

s/NET/Net/g; # ??

Hmm. Interesting (and thanks for pointing it out!).

As per my other post that wasn't the actual cause, but I'm surprised it
didn't mess things up in other ways. I know that Windows can get away
with the initial use having the wrong case due to the insensitive file
system, but I'd have thought I'd have got a "Can't locate method new via
package..." when I tried to create an object of that class? Running my
test script now with NET rather than Net, everything works just fine!?

Simon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top