Adam R. Frielink wrote:

> I cannot seem to work out the syntax for Using MIME::Lite through an
> SMTP server that requires authentication.
> 
> 
> I can send properly through a server that doesn't require authorization,
> so I need to work out the proper way to pass in authentication.
> 
> MIME::Lite->send('smtp', $mailtags{mailsmtp}, Timeout =>60);
> 
> 
> Is the 3rd parameter a hash?  If so, building the hash like:
> 
> $mailtags{mailauth} = "user,password";
> 
> 
> my %hSmtpparm;
> $hSmtpparm{Timeout}=60;
> $hSmtpparm{auth} = $mailtags{mailauth} if (exists($mailtags{mailauth}));
> MIME::Lite->send('smtp', $mailtags{mailsmtp}, %smtpparm);
> 
> 
> Since the Net::SMTP->auth is a method, do I need to create subroutine
> reference?  Any help is sorting this out would be appreciated.

You'd think someone would have had this problem before and gotten it
addressed.  Since 'auth' is a method and there is no equivalent form
saved in the class, I don't think the hash will help.

There are a few ways to try to solve it:

        Make your own version of send_by_smtp and use the send_by_sub
        method to call your sub (with auth processing added of course).

        Modify send_by_smtp to allow for an auth element and strip
        it off before the new call to Net::SMTP and then call the
        auth method after creating the object.  Just a few lines of
        code should fix it and you could pass it on to author.

        Build the message using MIME::lite and then use Net::SMTP to
        send it.

I'm not sure which way I'd go, but the thought of fixing send_by_smtp
has appeal.

I would try this for a start (I made 3 small mods to it):

sub send_by_smtp {
#   my ($self, @args) = @_;
    # @args changed to %args below $Bill 05/05/05
    my ($self, %args) = @_;

    ### We need the "From:" and "To:" headers to pass to the SMTP mailer:
    my $hdr  = $self->fields();
    my $from = $self->get('From');
    my $to   = $self->get('To');
    my $auth = delete ${'Auth'};

    ### Sanity check:
    defined($to) or Carp::croak "send_by_smtp: missing 'To:' address\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");
    # @args changed to %args below $Bill 05/05/05
    my $smtp = MIME::Lite::SMTP->new(%args)
        or Carp::croak("Failed to connect to mail server: $!\n");
    # if $auth added below $Bill 05/05/05
    if ($auth) {
        $smtp->auth($auth) or
            Carp::croak("SMTP AUTH command failed: $!\n".$smtp->message."\n");
    }
    $smtp->mail($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;
}


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to