Net::SMTP connection problems

S

Simon Andrews

Firstly let me say that I realise that this may not be a Perl issue, but
I think it must have some connection to the way that Net::SMTP works, so
bear with me!

I'm trying to connect to our local SMTP server. I did this ages ago
successfully but recently it's not working. Lots of stuff has changed
since it worked including new versions of perl and all modules, which
may or may not be relevant.

The problem boils down to:

#!perl
use warnings;
use strict;
use Net::SMTP;

my $smtp = Net::SMTP->new('smtp',
Timeout => 60,
Debug => 1);

print "Result was '$smtp' from ".$Net::SMTP::VERSION;


... which gets me:

Result was '' from 2.29 (plus an uninitialised value warning from trying
to print $smtp. It seems the connection is failing before the socket is
even created.

This is backed up by:
telnet smtp 25
Connecting To smtp...Could not open connection to the host, on port 25:
Connect failed

OK, so it seems the smtp server is blocking me.

However. If I run a local mail program (Thunderbird) on this machine
and point it to the same SMTP server on the same port it can send
messages successfully. I'm completely at a loss to explain how what
Thunderbird is doing could be any different to what I'm doing in the script.

A few things to rule out:

There is no authorisation needed on the server. Thunderbird is set up
not to provide any credentials.

Running the same script as above from a linux box in the same IP range
works as expected, it can also telnet in correctly. All windows boxes
I've tried fail. I've tried setting $/ to \012 in case that had any
bearing, but to no avail.

Our server admin swears that there are no rules in place on the server
to block this machine from connecting.

There is no local firewall on this machine which might selectively block
outgoing packets.

I've also tried all of this using IP addresses rather than host names.
No change in outcome.

Is there any possibility that there's something in the way perl is
creating the initial connection which could be different to what a
standalone mail program would be doing? I'm really at a loss as to how
to debug this.

Simon.
 
P

prawn

Connecting To smtp...Could not open connection to the host, on port 25:
Connect failed

OK, so it seems the smtp server is blocking me.

Assuming smtp is the correct name, then port 25 is blocked.


On my home network:

prawn@deepthought:~$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 deepthought.ryet.co.uk ESMTP Postfix (Ubuntu)

And from another machine:

Connection closed by foreign host.
prawn@eddie:~$ telnet deepthought 25
Trying 192.168.1.108...
telnet: Unable to connect to remote host: Connection refused

This is an smtp / network issue.
 
S

Sisyphus

..
..
#!perl
use warnings;
use strict;
use Net::SMTP;

my $smtp = Net::SMTP->new('smtp',
Timeout => 60,
Debug => 1);

print "Result was '$smtp' from ".$Net::SMTP::VERSION;


.. which gets me:

Result was '' from 2.29 (plus an uninitialised value warning from trying
to print $smtp. It seems the connection is failing before the socket is
even created.

Yep - I get exactly the same. On my box, I expect it's because there's no
accessible mail host by the name of 'smtp'.
Does specifying 'smtp' as the mail host normally work for you ? (eg, is
that's what specified on the linux boxes where the program *does* work ?)

Cheers,
Rob
 
S

Simon Andrews

Sisyphus said:
.
.

Yep - I get exactly the same. On my box, I expect it's because there's
no accessible mail host by the name of 'smtp'.
Does specifying 'smtp' as the mail host normally work for you ? (eg, is
that's what specified on the linux boxes where the program *does* work ?)

It's not that. The name smtp does resolve correctly on this machine and
the connection fails even if I use the fully qualified name or even the
IP address. Also using just smtp works fine if specified in the
Thunderbird config on this same machine.

My latest suspect for this is the Surf Control system we are forced to
use here, which has been known to interfere with port 25, although that
shouldn't produce different results on a per-application basis.

Is there more than one way to make a socket connection (at any level in
the IP stack) such that Perl and Thunderbird could be doing something
which appeared different to the receiving server?

Simon.
 
P

prawn

It's not that. The name smtp does resolve correctly on this machine and
the connection fails even if I use the fully qualified name or even the
IP address. Also using just smtp works fine if specified in the
Thunderbird config on this same machine.

Odd, I have run your code on my localhost and it works. Sooo...
My latest suspect for this is the Surf Control system we are forced to
use here, which has been known to interfere with port 25, although that
shouldn't produce different results on a per-application basis.

Try downloading Wireshark [1] http://wireshark.org and see what happens
when you send mail with your client of choice and compare with your perl
code.

HTH

[1] Formerly Ethereal.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top