in reply to Send and Receive Mail

You have to use the auth method defined in Net::SMTP, by doing this, you don't need to worry how to deal with the SASL (Simple Authentication and Security Layer).
$smtp->auth("myuid", "mypasswd");
MIME::Lite has a method called send_by_smtp, which allows you to pass parameters to the Net::SMTP object that MIME::Lite will create, but those are only the parameters will be passed to Net::SMTP->new, not the auth method we memtioned above.

MIME::Lite is mainly intended to allow you encode your mail msg, although it provided the send method as bonus, but it is never intended to be a full implementation of those RFC's. Even for msg encoding, it is not fully RFC-822 compliant.

If you are serious about the full implementation, the right way is only to use MIME::Lite as the MIME encoder, and to use Net::SMTP to deal with the mail server.

Replies are listed 'Best First'.
Re: Re: Send and Receive Mail
by filmo (Scribe) on Dec 15, 2002 at 00:49 UTC
    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