lv211 has asked for the wisdom of the Perl Monks concerning the following question:

My SMTP server is on 1and1.com. They only allow using their server through SMTP authentication.

Right now I'm just trying to access the server.

My code is:

#!/usr/bin/perl -w use strict; use Net::SMTP; my $mail_server = "smtp.1and1.com"; my $username = "login"; my $password = "password"; my $pop = Net::SMTP->new($mail_server) or die "Can't open connection to $mail_server: $!\n"; defined ($pop->auth($username, $password)) or die "Can't authenticate: $!\n";
I keep getting the error: Can't open connection to smtp.1and1.com unknown error

So I think the problem has to do with the initial connection to the server.

Replies are listed 'Best First'.
Re: SMTP Authentication
by imp (Priest) on Aug 24, 2006 at 23:57 UTC
    The code you provided works as is for me using perl 5.8.4 and Net::SMTP 2.29 on a redhat enterprise 4 machine.

    What operating system is this running on? Also what versions of perl and Net::SMTP?

    Update - It's possible that you can't connect to that port, possibly because of a firewall or local permissions issue. For example, when running in a CGI script people using Fedora sometimes have a problem with SELINUX

    Try this in the shell:

    telnet smtp.1and1.com 25
    If you can connect you should see this:
    Trying 217.160.226.98... Connected to smtp.1and1.com. Escape character is '^]'. 220 smtp.perfora.net (mrelayus1) Welcome to Nemesis ESMTP server
Re: SMTP Authentication
by GrandFather (Saint) on Aug 25, 2006 at 00:08 UTC

    Fails for me as described using AS Perl 5.8.7 on Windows XP with Net::SMTP 2.29.


    DWIM is Perl's answer to Gödel
      Are you able to connect to smtp.1and1.com on port 25 from that location? Try this in the cmd shell:
      telnet smtp.1and1.com 25
      I just tested the code from a Win2000 machine with AS perl 5.6.1 and Net::SMTP 2.26 with no issues. I did get that error on a local WinXP machine that cannot make outbound connections to port 25 though.

        Nope. Connect failed. Firewall I guess, but turning off my Windows firewall makes no difference.


        DWIM is Perl's answer to Gödel
      Many ISP's block outgoing connections on port 25 in order to reduce the amount of spam being sent from accounts in their networks and to block viruses that try to use port 25 to send emails direct to their targets.

      Try port 587 or port 857 on the SMTP server. I believe that many SMTP servers can be configured to listen on multiple ports so that you can get around a port 25 block.

      jdtoronto

Re: SMTP Authentication
by lv211 (Beadle) on Aug 25, 2006 at 00:19 UTC
    I'm using the same setup grandfather is using. I was able to access the server using port 587. How do I integrate this into my code?
      my $pop = Net::SMTP->new($mail_server, Port => 587) or die "Can't open connection to $mail_server:
Re: SMTP Authentication
by lv211 (Beadle) on Aug 25, 2006 at 00:27 UTC
    I'm in.

    Thanks for your help imp.

    Is there a way I can give you rep or am I still to new to do anything?