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

I've been tearing my hair out over this one. All I'm trying to do is to get perl to do what I can already do by telnetting to my mail server over port 25 and entering in all the details manually.

When I telnet in, I use auth login and then enter the username and password in Base64. This works fine.

Now I want to get perl to do the same, so after much consultation of CPAN and throwing away Mail::Mailer as useless, I wrote the following (sanitised, of course):

#!/usr/bin/perl # # use strict; use Net::SMTP; my $DEBUG = 1; my $smtp; $smtp = Net::SMTP->new('mymailserver.net', Hello => "myotherserver.net +", Debug => 1,); die "Couldn't connect to server" unless $smtp; print "Server connection opened\n"; $smtp->auth('myuser', 'test123'); ...

When I run this, I get the following:

Net::SMTP>>> Net::SMTP(2.31) Net::SMTP>>> Net::Cmd(2.29) Net::SMTP>>> Exporter(5.58) Net::SMTP>>> IO::Socket::INET(1.29) Net::SMTP>>> IO::Socket(1.29) Net::SMTP>>> IO::Handle(1.25) Net::SMTP=GLOB(0xa6fd440)<<< 220 mymailserver.net ESMTP Exim 4.60 Mon, + 20 Jul 2009 15:08:52 +0100 Net::SMTP=GLOB(0xa6fd440)>>> EHLO myotherserver.net Net::SMTP=GLOB(0xa6fd440)<<< 250-mymailserver.net Hello myotherserver. +net [10.1.2.70] Net::SMTP=GLOB(0xa6fd440)<<< 250-SIZE 20971520 Net::SMTP=GLOB(0xa6fd440)<<< 250-PIPELINING Net::SMTP=GLOB(0xa6fd440)<<< 250-AUTH PLAIN LOGIN Net::SMTP=GLOB(0xa6fd440)<<< 250-STARTTLS Net::SMTP=GLOB(0xa6fd440)<<< 250 HELP Server connection opened Net::SMTP=GLOB(0xa6fd440)>>> AUTH PLAIN bXl1c2VybXl1c2VydGVzdDEyMw== Net::SMTP=GLOB(0xa6fd440)<<< 535 Incorrect authentication data ...

The problem seems to be twofold:

  1. Instead of using AUTH LOGIN, it's using AUTH PLAIN
  2. The Base64 string contains the username twice, then the password, which is wrong.

Is this a bug in Net::SMTP, or a problem with my mail server, or something else?

Replies are listed 'Best First'.
Re: Net::SMTP auth login fails - passes in username twice!
by jrsimmon (Hermit) on Jul 20, 2009 at 14:46 UTC
    A super search for Net::SMTP and auth found several threads referencing Net::SMTP and the auth() method, notably this one. It suggests that you need to have either Authen::SASL::Cyrus or Authen::SASL::Perl installed for the auth() method to function properly.
      I already have Authen::SASL installed.
Re: Net::SMTP auth login fails - passes in username twice!
by ultrarunner (Initiate) on Dec 31, 2016 at 03:44 UTC

    I'm having this same problem (yes, seven years later) and this is the only post I've found that matches.

    As part of some trial and error I was doing to try to understand what the code (I'm not very good at perl syntax), I tried changing the name of the auth function in SMTP_auth. I was surprised to get an error saying perl could not find the function in Net::SMTP::_SSL. So I changed the ISA in Net::SMTP::_SSL from Net::SMTP to Net::SMTP_auth and AUTH LOGIN worked! I'm not sure how a call to Net::SMTP_auth->auth() ended up getting routed through Net::SMTP::_SSL but it's clear that doing so would be a problem since the auth in Net::SMTP::_SLL has a different number of parameters from the one in Net::SMTP_auth.

    So, while I don't have a fix for the problem (other than to hack the ISA in Net::SMTP::_SSL), I'm hoping someone smarter than me can use what I've found to make a proper fix.

      There is a huge difference in the versions of Net::SMTP between 2009 and 2016 and you are fiddling in your post which parts which did not even exist in 2009 (i.e. SSL support). If you really want to have help in your problem please ask a new question with a proper problem description, way to reproduce the problem and the Perl and Net::SMTP version you use. Based on this one could actually try to help you.
Re: Net::SMTP auth login fails - passes in username twice!
by Anonymous Monk on Jul 20, 2009 at 15:03 UTC
    Instead of using AUTH LOGIN, it's using AUTH PLAIN The SMTP server tells it OK to use AUTH PLAIN
    Net::SMTP=GLOB(0xa6fd440)<<< 250-AUTH PLAIN LOGIN Net::SMTP=GLOB(0xa6fd440)>>> AUTH PLAIN
    PLAIN is listed before LOGIN.

    2. The Base64 string contains the username twice, then the password, which is wrong. Is this a bug in Net::SMTP, or a problem with my mail server, or something else?

    Maybe, check for updates

    perl -MDevel::Modlist -MNet::SMTP -e 1 Carp 1.10 Config Errno 1.1 Exporter 5.63 Exporter::Heavy 5.63 IO 1.25 IO::Handle 1.28 IO::Socket 1.31 IO::Socket::INET 1.31 IO::Socket::UNIX 1.23 Net::Cmd 2.29 Net::Config 1.11 Net::SMTP 2.31 SelectSaver 1.01 Socket 1.81 Symbol 1.06 XSLoader 0.10 utf8 1.07 vars 1.01 warnings 1.05_01 warnings::register 1.01
Re: Net::SMTP auth login fails - passes in username twice!
by Khen1950fx (Canon) on Jul 21, 2009 at 00:12 UTC
    I've been scratching my head over this one. The answer seemed like it would be simple, but I encountered a few exceptions.

    First, I noticed that you were using TLS, so I tried it with Net::SMTP::TLS. The problem there for me was that the module requires Net::SSLeay, but that's broken and won't work for me.

    Second, all the servers that I use basically use the two mechanisms, DIGEST-MD5 and CRAM-MD5, so LOGIN wasn't available and even PLAIN wasn't always available.

    Third, wondering why the LOGIN mechanism seemed to be awol somewhere, I figured that this stuation was a "gotcha". See the internet draft The LOGIN SASL Mechanism for more details.

      requires Net::SSLeay, but that's broken and won't work for me.

      How so?

        How so

        It installed ok, but every time that I try to use it, I get:

        Net/SSLeay/SSLeay.so: undefined symbol: SSL_load_error_strings

        Any ideas?