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

Dear Monks, I'm trying to set up Net::SMTP to send emails through my SMTP server using the follow code:
use Net::Cmd; use Net::SMTP; my $smtp = Net::SMTP->new($mailserver) || die $!; #print p("Couldn't create the smtp object"); $smtp->auth($username, $password) or die "Can't authenticate: $!\n";
and i get the following error:

Can't locate Authen/SASL.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.8.7/mach /usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl/5.8.0 /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.8.7/BSDPAN /usr/local/lib/perl5/5.8.7/mach /usr/local/lib/perl5/5.8.7 .) at /usr/local/lib/perl5/site_perl/5.005/Net/SMTP.pm line 102.

any idea what i'm doing wrong? TIA, janaki

Replies are listed 'Best First'.
Re: Net::SMTP auth fails
by jettero (Monsignor) on Feb 14, 2007 at 18:37 UTC

    It says you don't have the Authen::SASL module installed. It is required for the auth function. If you can get by without calling auth, then just comment that out, otherwise issue a "perl -MCPAN -e 'install Authen::SASL'" and you should be all set — after some effort.

    -Paul

Re: Net::SMTP auth fails
by chargrill (Parson) on Feb 14, 2007 at 18:38 UTC

    Try installing Authen::SASL?

    Looks like it got missed as a prerequisite when you installed Net::SMTP, or you forced the install, or ignored the warning that probably said something along the lines of "if you try to authenticate via X you'll need the optional module Authen::SASL"

    But that's just a guess.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
Re: Net::SMTP auth fails
by marto (Cardinal) on Feb 14, 2007 at 18:38 UTC
    Hi jck,

    Do you have the Authen::SASL module installed?

    Hope this helps

    Martin
Re: Net::SMTP auth fails
by jck (Scribe) on Feb 14, 2007 at 18:46 UTC
    Thanks, everyone, for the quick response....so much for RTFM - did i miss it when it mentioned this requirement?

    I'll load up Authen::SASL now!

      Not so much that you missed something but that you didn't know you were missing something. If you look at the docs for Net::SMTP::auth() you'll see it mentions SASL. It doesn't mention needing Authen::SASL installed though, so there's no real reason to think you need that.

      However, when you get the "Can't Locate" message it usually means you need to install something (or reinstall it properly). I have Net::SMTP on my machine and it works fine without Authen::SASL installed. But I don't use auth().