use strict;
use warnings;
use Net::SMTP;

my $mailhost = "mail.bob.com";
my $mailobj = "";
if($mailobj = Net::SMTP->new($mailhost, Timeout=>10, Debug=>1)){
        print("Connected to $mailhost\n");
} else {
        print("Could not connect to $mailhost\n");
        die;
}


my $username = "[EMAIL PROTECTED]";
my $password = "jimmy";

$mailobj->auth($username,$password);
my $Rx1 = "[EMAIL PROTECTED]";
my $Rx2 = "[EMAIL PROTECTED]";
my $from = "[EMAIL PROTECTED]";
print("The recipients are $Rx1 and $Rx2\n");
$mailobj->mail($from);
$mailobj->recipient($Rx1, $Rx2,{SkipBad=>1});

if($mailobj->data()){
        $mailobj->datasend("To:$Rx1\r\n");
        $mailobj->datasend("cc:$Rx2\r\n");
        $mailobj->datasend("Subject: Email from Perl script using
bob.com with authentication\r\n");
        $mailobj->datasend("This is a test message\n");
        print("Data sent successfully \n");
} else {
        print("Send failed\n");
}



$mailobj->quit;


#This worked, with subject, to and cc fields.
#make sure the Auth::SASL module is installed.

You get the idea.

Cheers,
john

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of $Bill Luebkert
> Sent: Sunday, December 19, 2004 11:52 AM
> To: Bennett Haselton
> Cc: [EMAIL PROTECTED]
> Subject: Re: how to send mail from Win32 Perl using SMTP 
> authentication?
> 
> 
> Bennett Haselton wrote:
> 
> > Does anybody have any sample code for sending mail from a 
> Perl script 
> > on
> > Windows, through an SMTP server that requires SMTP authentication?
> > 
> > I have a script where I wrote the logic in fifteen minutes and then 
> > have
> > spent about three hours trying to look up a way for Perl to 
> simply send the 
> > email.  I found the Mail::Mailer module but its 
> documentation page says it 
> > specifically doesn't support SMTP authentication.  I found the 
> > Net::SMTP_auth module searching PPM modules for "SMTP", but 
> the sample code 
> > given in the documentation:
> > 
> > $smtp->auth('CRAM-MD5', 'user', 'password');
> > 
> > only shows how set the authentication method to "CRAM-MD5".  It 
> > doesn't
> > list any other valid values that are accepted for the 
> authentication 
> > method.  It does say that I can use this code:
> > 
> > $smtp = Net::SMTP_auth->new('mail.speakeasy.net');
> > print $smtp->auth_types();
> > 
> > to find out what authentication types are supported by 
> > mail.speakeasy.net;
> > when I do that, the only value returned is "LOGINPLAIN", 
> and if I try this 
> > code:
> > 
> > $smtp->auth('LOGINPLAIN', 'user', 'password');
> > 
> > I get the error:
> > 
> > No SASL mechanism found
> >   at C:/Perl/site/lib/Authen/SASL.pm line 62
> > 
> > which I assume is the generic error meaning the 
> Net::SMTP_auth module
> > doesn't support that authentication type, since it's the 
> same error I get 
> > if I try using a junk authentication type e.g.
> > 
> > $smtp->auth('FOOBAR', 'user', 'password');
> 
> Try using just plain Net::SMTP module - there is an auth 
> method, but not sure if it's dependent on Authen::SASL or not.
> 
> -- 
>   ,-/-  __      _  _         $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 [EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to