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


I am using the following code to send a test mail:

use Net::SMTP; $smtp = Net::SMTP->new('; $smtp->auth('myusername', 'mypassword'); $smtp->mail(''); $smtp->to(''); $smtp->data(); $smtp->datasend("Subject: test smtp\n"); $smtp->datasend("test\n"); $smtp->dataend(); $smtp->quit;

It works precisely in one system, whereas it is showing up the following error in another system:

Unknown callback: 'authname'. (user|auth|language|pass)

Any idea?


Replies are listed 'Best First'.
Re: Net::SMTP - Authentication Problem
by zentara (Archbishop) on Aug 29, 2006 at 12:06 UTC
    Maybe try the Net::SMTP_auth module?
    #!/usr/bin/perl use warnings; use strict; use Net::SMTP_auth; my $smtp = Net::SMTP_auth->new(''); $smtp->auth('LOGIN', 'z', 'ztest'); $smtp->mail(''); $smtp->to(''); $smtp->data(); $smtp->datasend("To: postmaster\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); $smtp->quit;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      use Net::SMTP::TLS

      It's the version made to properly support authentication. For whatever reason, Net::SMTP seems not to.

      I tried SMTP_auth as you have suggested. It also fails. I check this in the system in which Net::SMTP works, it works in that system precisely.

      Kindly let me know if you have any suggestions.


        One of the things I can think of, is the auth_type is wrong. I showed a 'LOGIN' auth_type, but there is a choice of PLAIN, LOGIN, or CRAM-MD5.

        Also try turning on Debug and see if you can catch the error.

        my $smtp = Net::SMTP_auth->new($Servername, Port=>$Port, Debug => 1 );

        You also might want to capture the transaction with ethereal or tcpick

        Did you ever consider the other system dosn't support SMTP auth? Or the port it runs it on is different from the working system? Many systems run auth on port 587, but they can put it wherever they want.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Net::SMTP - Authentication Problem
by dtr (Scribe) on Aug 29, 2006 at 11:38 UTC

    Net::SMTP uses Authen::SASL internally to do the authentication. You should check to make sure that this is installed on both machines. Authen::SASL comes in several flavours, including Authen::SASL::Perl (pure perl) and Authen::SASL::Cyrus (using XS to link to the cyrus libraries). Check that you have the same one installed on both systems.

    You're not doing any error checking in the above code either. You should make sure that each of the auth(), mail(), to(), and data() functions return a true value, and if they do not, use the $smtp->message() method to get the error message back.

    You can use Ethereal to look at what is actually being sent to your mail server too - this is sometimes useful

      Please note that both the systems are having same versions of Authen::SASL::Perl.

      I tried $smtp->message. For "new" I get the following output: PIPELINING SIZE 20480000 VRFY ETRN AUTH PLAIN LOGIN 8BITMIME

      For "auth" I am not getting any return values, instead:

      Unknown callback: 'authname'. (user|auth|language|pass)

      Now, I am trying with Ethereal to troubleshoot this.

      By the way if you have any more suggestions please let me know.


Re: Net::SMTP - Authentication Problem
by Khen1950fx (Canon) on Aug 29, 2006 at 11:30 UTC
    If it works on one system, but you get an error message on another, then it's probably a protocol problem. You might try using Authen::SASL. It's designed so that all protocols can share the connection.


    For an interesting article on SMTP AUTH, see:

    SMTP AUTH in sendmail 8.10-8.13

Re: Net::SMTP - Authentication Problem
by Anonymous Monk on Aug 29, 2006 at 14:56 UTC
    Please don't use color for your code.