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

In reply to Re: Re: Send and Receive Mail by filmo
in thread Send and Receive Mail by filmo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.