Ended up adding this quick and dirty routine to MIME::Lite and it seems to work for authentication. I don't know much about writing modules, but I'm sure there probably a more gracefull and modular way to do the same.
sub send_by_smtp_with_auth {
my ($self, $user, $passwd, @args) = @_;
### We need the "From:" and "To:" headers to pass to the SMTP mail
+er:
my $hdr = $self->fields();
my $from = $self->get('From');
my $to = $self->get('To');
(my $corrected_from = $from) =~ s/.*<\s*(.*)>.*/$1/;
### Sanity check:
defined($to) or Carp::croak "send_by_smtp: missing 'To:' address\n
+";
defined($user) or Carp::croak "send_by_smtp: missing 'Login Acct'
+\n";
defined($passwd) or Carp::croak "send_by_smtp: missing 'passwd'\n
+";
defined(@args) or Carp::croak "send_by_smtp: missing \@args\n";
### Get the destinations as a simple array of addresses:
my @to_all = extract_addrs($to);
if ($AUTO_CC) {
foreach my $field (qw(Cc Bcc)) {
my $value = $self->get($field);
push @to_all, extract_addrs($value) if defined($value);
}
}
### Create SMTP client:
require Net::SMTP;
my $smtp = MIME::Lite::SMTP->new(@args)
or Carp::croak("Failed to connect to mail server: $!\n");
if ($user and $passwd) {
$smtp->auth($user,$passwd)
or Carp::croak("SMTP MAIL authorization failed: $!\n". $sm
+tp->message . "\n");
}
$smtp->mail($corrected_from)
or Carp::croak("SMTP MAIL command failed: $!\n".$smtp->message
+."\n");
$smtp->to(@to_all)
or Carp::croak("SMTP RCPT command failed: $!\n".$smtp->message
+."\n");
$smtp->data()
or Carp::croak("SMTP DATA command failed: $!\n".$smtp->message
+."\n");
### MIME::Lite can print() to anything with a print() method:
$self->print_for_smtp($smtp);
$smtp->dataend();
$smtp->quit;
1;
}
--
Filmo the Klown