Net::SMTP with username & password

B

Bob

I am using Net::SMTP as shown (works) but the server in question
will require a username/password before sending.

Does anyone have a sample of a program that shows those parameters
being supplied ?.

$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$body\n");
$smtp->dataend();
$smtp->quit;

Thanks,
 
U

usenet

Bob said:
I am using Net::SMTP as shown (works) but the server in question
will require a username/password before sending.

Does anyone have a sample of a program that shows those parameters
being supplied ?.


use Net::SMTP_auth;

$smtp = Net::SMTP_auth->new('mailhost');
$smtp->auth('CRAM-MD5', 'user', 'password');
 
B

Bob

use Net::SMTP_auth;

$smtp = Net::SMTP_auth->new('mailhost');
$smtp->auth('CRAM-MD5', 'user', 'password');

David:

So, the complete stream would look like this (less user/pass) ?

use Net::SMTP;

# next 2 lines no longer needed - replace with David's Code
# my $relay="mail.myserver.com";
# my $smtp = Net::SMTP->new($relay);

my $smtp = Net::SMTP_auth->new('mailhost');
$smtp->auth($relay, 'user', 'password');
die "Could not open connection: $!" if (! defined $smtp);

# other code same as before
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
<etc...>
$smtp->dataend();
$smtp->quit;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top