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

Hi Monks. I have a script that has been sending mail using Net::SMTP for a while now quite successfully. I recently was asked by my supervisor to add the ability to authenticate in that email script. I added the use Net::SMTP_auth() statement, and then got messages saying it can't find that package. ("Can't locate Net/SMTP_auth.pm")

Another server that I access sometimes also doesn't seem to know what SMTP_auth is. Is it part of the usual Perl? I thought it would be in there by now. I'm on Perl 5.8.4 & 5.8.8 on another server.

I found the post which lists the source code at http://www.perlmonks.org/?node_id=110334 but it's there as a package. I would perhaps need to cut & paste the code into my code??? but it would need modifications for that. Actually, can I used authentication with just Net::SMTP?

Any help you can offer would be great.

Replies are listed 'Best First'.
Re: Net::SMTP_auth install & usage
by thomas895 (Deacon) on Jun 05, 2012 at 21:27 UTC

      Can I do authentication without it? Otherwise, how do I go about installing it. (I'm a Perl user, not a server guru).

      Better yet, can I copy the two or three functions that it has in it into my own code? It will move between servers better that way. I think I saw at the end of the script it is free to do that with.

        Can I do authentication without it?
        If Net::SMTP does not provide authentication, then it does not provide authentication. So no, probably not.

        Better yet, can I copy the two or three functions that it has in it into my own code? It will move between servers better that way.
        You can, but what's the point? Just call cpan Net::SMTP_auth on your other machine, and it will install for you. You can even install it to a different directory, such as your project's library. All you would need to do is change the way you call Makefile.PL:

        $ cd ~/Desktop/Net-SMTP_auth-0.08 $ perl Makefile.PL LIB=/home/me/projects/myproject-1.0/lib

        The rest is the same.

        ~Thomas~
        confess( "I offer no guarantees on my code." );
Re: Net::SMTP_auth install & usage
by Khen1950fx (Canon) on Jun 06, 2012 at 03:52 UTC
    I tried it with Authen::SASL. You'll need to use a callback:
    #!/usr/bin/perl -l BEGIN { $| = 1; require MIME::Base64; require Authen::SASL; } use strict; use autodie; use warnings; use Net::SMTP; my $host = 'mailhost'; my $user = 'user'; my $pass = 'pass'; my $smtp = Net::SMTP->new( Host => $host, Hello => 'your.mail.domain', Time => 30, Debug => 1, ); my $sasl; my $mechanisms = ['AUTH', 500]; die "Couldn't login: $!" unless \&auth; sub auth { my $sasl = Authen::SASL->new( mechanism => $mechanisms, debug => 1, callback => { user => $user, pass => $pass, authname => $user, } ); }

      What would be the advantage of using Authen::SASL over Net::SMTP_auth? Hmmm, OK, I just read through the source code for SMTP_auth again and realized it's using the Authen::SASL to do the work anyway - is that right? I'm new to this you see :) Is it just a wrapper for SASL authentication?

      My code is used on client machines, and I have no control over what the clients have installed or not, many of them with an ISP that won't install things just for me. (like SMTP_auth). That's why I asked earlier about transferring the code into my script, I can have it with me anywhere I (or my script) might go.

        I used Authen::SASL because because it has fewer dependencies. Net::SMTP_auth is built on top of Authen::SASL, but your clients are more likely to have Authen::SASL installed.