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

Hello Guys!!

I'm working with MIME::Lite and qmail, right now i'm using authentification but it work some time and other not, why? becouse the server only use plain authentification but some times inform that support cram-md5.

So, exists a way to force plain method of authentification

Now i'm using this code, very simple:

#!/usr/bin/perl use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->new( From => 'from@isp.com', To => 'to@isp.com', Subject => 'Subject', Type => 'text/plain', Data => q{this's an email!!} ); $msg->send('smtp','stmp.myisp.com', AuthUser=>'user',AuthPass=> 'pass' +);

Please, note that i guest that this's the problem, becouse if i'm not wrong, the method to authentification is selected with the response of server and i can see two different response of ehlo.

the error when it fail is "authorization failed (#5.7.0)"

Ugly but functional:

#!/usr/bin/perl use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->new( From => 'from@isp.com', To => 'to@isp.com', Subject => 'Subject', Type => 'text/plain', Data => q{this's an email!!} ); my $smtp = My::SMTP->new('stmp.isp.com', Debug => 4) or die $!; $smtp->auth('user','pass'); $smtp->mail('from@isp.com'); $smtp->to('to@isp.com'); $smtp->data(); $smtp->datasend($msg->as_string()); $smtp->dataend(); $smtp->quit; package My::SMTP; use strict; use warnings; use base qw(Net::SMTP); use Net::Cmd; our $VERSION = 0.01; sub auth { my ($self, $username, $password) = @_; eval { require MIME::Base64; require Authen::SASL; } or $self->set_status(500, ["Need MIME::Base64 and Authen::SASL tod +o auth"]), return 0; my $mechanisms = 'PLAIN'; return unless defined $mechanisms; my $sasl; if (ref($username) and UNIVERSAL::isa($username, 'Authen::SASL')) { $sasl = $username; $sasl->mechanism($mechanisms); } else { die "auth(username, password)" if not length $username; $sasl = Authen::SASL->new( mechanism => $mechanisms, callback => { user => $username, pass => $password, authname => $username, } ); } # We should probably allow the user to pass the host, but I don't # currently know and SASL mechanisms that are used by smtp that need + it my $client = $sasl->client_new('smtp', ${*$self}{'net_smtp_host'}, 0 +); my $str = $client->client_start; # We dont support sasl mechanisms that encrypt the socket traffic. # todo that we would really need to change the ISA hierarchy # so we dont inherit from IO::Socket, but instead hold it in an attr +ibute my @cmd = ("AUTH", $client->mechanism); my $code; push @cmd, MIME::Base64::encode_base64($str, '') if defined $str and length $str; while (($code = $self->command(@cmd)->response()) == CMD_MORE) { @cmd = ( MIME::Base64::encode_base64( $client->client_step(MIME::Base64::decode_base64(($self->messa +ge)[0])), '' ) ); } $code == CMD_OK; } 1;

Replies are listed 'Best First'.
Re: Select the method of authentification on MIME::Lite
by Krambambuli (Curate) on Nov 20, 2008 at 07:49 UTC
    Try maybe
    $msg->send( 'smtp', 'stmp.myisp.com', AuthUser => 'user', AuthPass => 'pass', AUTH => 'PLAIN', Debug => 1, );
    and see if that helps.

    Krambambuli
    ---

      No, my friend, it continue using cram-md5

      Checking the internal it only allow send this commnand to net::smtp

      my @_net_smtp_opts = qw( Hello LocalAddr LocalPort Timeout ExactAddresses Debug );

      Anyway, i updated with a ugly solution but functional, this happend i think becouse a wrong configuration of qmail, so no much server are afected.

      Thank you

Re: Select the method of authentification on MIME::Lite
by zentara (Cardinal) on Nov 19, 2008 at 19:35 UTC
    According to the perldocs, you can add NoAuth=>1 as an option.

    I'm not really a human, but I play one on earth Remember How Lucky You Are

      No, look, if i add NoAuth => 1 MIME::Lite don't send the authentification data

      Any idea how force to plain authentification?

      Thank you