[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-mailbox
Subject: Re: Mail::Transport::SMTP - options username password do not work
From: Michael de Beer <madebeer () apc ! org>
Date: 2002-10-06 19:10:24
[Download RAW message or body]
On Sun, Oct 06, 2002 at 02:18:17PM +0200, Mark Overmeer wrote:
> * Michael de Beer (madebeer@apc.org) [021005 19:47]:
> > Has anyone gotten 'username' and 'password' to work?
> > Are there patches?
>
> How do you expect them to work with the SMTP protocol?
Maybe I misunderstand what username and password are for.
I thought this was NOT the unix username and password of the local
host, but rather the username and password on the SMTP server -- for
doing ESMTP/SASL authorization to use an SMTP server.
What I need to do is ESMTP/SASL authorization on a (possibly remote)
SMTP server.
If I was to call the Net::SMTP code directly, I would do this to do
ESMTP auth: (see especially the 'if' block with $smtp->auth() )
---
my $smtp = Net::SMTP->new($host, %smtp_options);
$smtp or die "failed to connect to SMTP server";
if ($username) {
print "WARNING: failed ESMTP auth using username '$username'...trying to send \
anyway\n" unless $smtp->auth ($username, $password); };
$smtp->mail($from) or die "server rejected FROM address '$from'";
$smtp->to(@rcpt, {SkipBad => 1}) or die "server rejected all TO addresses";
$smtp->data() or die "server crashed while preparing to send DATA";
$smtp->datasend($txt_head) or die "server crashed while sending DATA.1";
$smtp->datasend("\n") or die "server crashed while sending DATA.2";
$smtp->datasend($txt_body) or die "server crashed while sending DATA.3";
$smtp->dataend() or die "server crashed while ending DATA";
$smtp->quit or die "server crashed while quiting - message may not be lost";;
--
By the way, in my particular situation, Net::SMTP::Auth did not work
with the mechanism 'LOGIN', but did work with the mechanism 'PLAIN'.
made a new function called Net::SMTP::ext_auth that let me choose
the mechanism (and I chose PLAIN). In case you have the same problem,
here is that function:
#--------------------
package Net::SMTP;
sub ext_auth { # taken from Net::SMTP, only modify $mechanisms
my ($self, $username, $password, $mechanisms) = @_;
require MIME::Base64;
require Authen::SASL;
my $m = $self->supports('AUTH',500,["Command unknown: 'AUTH'"]);
return unless defined $m;
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,
});
}
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 attribute
my @cmd = ("AUTH", $client->mechanism, MIME::Base64::encode_base64($str,''));
my $code;
while (($code = $self->command(@cmd)->response()) == CMD_MORE) {
@cmd = (MIME::Base64::encode_base64(
$client->client_step(
MIME::Base64::decode_base64(
($self->message)[0]
)
), ''
));
}
$code == CMD_OK;
}
# if including this , remember to use package PACKAGENAME to get back
# in your own context, probably 'main' or 'Mail::Box'
--------------------
Thanks,
Michael
> > http://Mark.Overmeer.net http://solutions.overmeer.net
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic