Net::SMTP connection problems

Discussion in 'Perl Misc' started by Simon Andrews, Mar 8, 2007.

  1. 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.
     
    Simon Andrews, Mar 8, 2007
    #1
    1. Advertising

  2. Simon Andrews

    prawn Guest

    On 2007-03-08, Simon Andrews <> wrote:
    > >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.


    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.
    --
    p BotM#1 LotR#9
     
    prawn, Mar 8, 2007
    #2
    1. Advertising

  3. Simon Andrews

    Sisyphus Guest

    "Simon Andrews" <> wrote in message
    news:esorml$3rr$...
    ..
    ..
    >
    > #!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
     
    Sisyphus, Mar 9, 2007
    #3
  4. Sisyphus wrote:
    >
    > "Simon Andrews" <> wrote in message
    > news:esorml$3rr$...
    > .
    > .
    >>
    >> #!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 ?)


    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.
     
    Simon Andrews, Mar 9, 2007
    #4
  5. Simon Andrews

    prawn Guest

    On Fri, 09 Mar 2007 15:01:34 +0000, Simon Andrews wrote:

    > 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.
    --
    p BotM#1 LotR#9
     
    prawn, Mar 9, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    40,435
    Roedy Green
    Nov 16, 2005
  2. Replies:
    3
    Views:
    1,103
    Roedy Green
    Jan 24, 2006
  3. Alex Hunsley
    Replies:
    4
    Views:
    3,561
    Tim Williams (gmail)
    Jun 29, 2004
  4. Raaijmakers, Vincent \(GE Infrastructure\)

    RE: sending of mail (smtp) - connection refused - but smtp serveris running!

    Raaijmakers, Vincent \(GE Infrastructure\), Jun 29, 2004, in forum: Python
    Replies:
    0
    Views:
    894
    Raaijmakers, Vincent \(GE Infrastructure\)
    Jun 29, 2004
  5. Copelandia Cyanescens

    smtplib.SMTP "no attributes SMTP"

    Copelandia Cyanescens, Jul 31, 2004, in forum: Python
    Replies:
    2
    Views:
    1,482
    Copelandia Cyanescens
    Jul 31, 2004
Loading...

Share This Page