Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   SMPT Connection Errors (http://www.velocityreviews.com/forums/t889435-smpt-connection-errors.html)

Simon Andrews 12-01-2004 01:55 PM

SMPT Connection Errors
 
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('simon.andrews@bbsrc.ac.uk');

$smtp -> to('simon.andrews@bbsrc.ac.uk');
$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 => 'simon.andrews@bbsrc.ac.uk',
From => 'simon.andrews@bbsrc.ac.uk',
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();

Simon Andrews 12-01-2004 02:32 PM

Re: SMPT Connection Errors
 
Simon Andrews wrote:
> 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.

Tad McClellan 12-01-2004 02:49 PM

Re: SMPT Connection Errors
 
Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote:
>
> other uses MIME::Lite (which itself uses Net::SMTP for the connection).

^^^

> use NET::SMTP;
>
> $NET::SMTP::Debug = 1;

^^^


s/NET/Net/g; # ??


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Simon Andrews 12-01-2004 04:04 PM

Re: SMPT Connection Errors
 
Tad McClellan wrote:
> Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote:
>
>>other uses MIME::Lite (which itself uses Net::SMTP for the connection).

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

>
> ^^^
>
> 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.






All times are GMT. The time now is 06:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57