0

Hello,

I am trying to send e-mail using Perl and Net::SMTP::SSL. However, I receive errors when running this script (example from documentation):

#!/usr/bin/perl -w

use Net::SMTP::SSL;

sub send_mail {
my $to = $_[0];
my $subject = $_[1];
my $body = $_[2];

my $from = 'me@gmail.com';
my $password = 'MySuperSecretPassword';

my $smtp;

if (not $smtp = Net::SMTP::SSL->new('smtp.gmail.com',
                            Port => 465,
                            Debug => 1)) {
   die "Could not connect to server\n";
}

$smtp->auth($from, $password)
   || die "Authentication failed!\n";

$smtp->mail($from . "\n");
my @recepients = split(/,/, $to);
foreach my $recp (@recepients) {
    $smtp->to($recp . "\n");
}
$smtp->data();
$smtp->datasend("From: " . $from . "\n");
$smtp->datasend("To: " . $to . "\n");
$smtp->datasend("Subject: " . $subject . "\n");
$smtp->datasend("\n");
$smtp->datasend($body . "\n");
$smtp->dataend();
$smtp->quit;
}

# Send away!
&send_mail('name@example.com', 'Server just blew up', 'Some more detail');

Naturally, I change the value of from, to, and password to be their correct values when I run the script.

However, I receive errors like this:

Net::SMTP::SSL>>> Net::SMTP::SSL(1.01)
Net::SMTP::SSL>>>   IO::Socket::SSL(1.30)
Net::SMTP::SSL>>>     IO::Socket::INET(1.31)
Net::SMTP::SSL>>>       IO::Socket(1.30_01)
Net::SMTP::SSL>>>         IO::Handle(1.27)
Net::SMTP::SSL>>>           Exporter(5.62)
Net::SMTP::SSL>>>   Net::Cmd(2.29)
Net::SMTP::SSL=GLOB(0x2065958)<<< 220 mx.google.com ESMTP y6sm320414mug.40
Net::SMTP::SSL=GLOB(0x2065958)>>> EHLO localhost.localdomain
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-mx.google.com at your service, [128.113.81.58]
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-SIZE 35651584
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-8BITMIME
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-AUTH LOGIN PLAIN
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP::SSL=GLOB(0x2065958)<<< 250 PIPELINING
Authentication failed!

And yes, I am certain that all the values I am using are valid.

Any thoughts about this?

Edited by ItecKid: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by simfex
0

Hello,

I am trying to send e-mail using Perl and Net::SMTP::SSL. However, I receive errors when running this script (example from documentation):

#!/usr/bin/perl -w

use Net::SMTP::SSL;

sub send_mail {
my $to = $_[0];
my $subject = $_[1];
my $body = $_[2];

my $from = 'me@gmail.com';
my $password = 'MySuperSecretPassword';

my $smtp;

if (not $smtp = Net::SMTP::SSL->new('smtp.gmail.com',
                            Port => 465,
                            Debug => 1)) {
   die "Could not connect to server\n";
}

$smtp->auth($from, $password)
   || die "Authentication failed!\n";

$smtp->mail($from . "\n");
my @recepients = split(/,/, $to);
foreach my $recp (@recepients) {
    $smtp->to($recp . "\n");
}
$smtp->data();
$smtp->datasend("From: " . $from . "\n");
$smtp->datasend("To: " . $to . "\n");
$smtp->datasend("Subject: " . $subject . "\n");
$smtp->datasend("\n");
$smtp->datasend($body . "\n");
$smtp->dataend();
$smtp->quit;
}

# Send away!
&send_mail('name@example.com', 'Server just blew up', 'Some more detail');

Naturally, I change the value of from, to, and password to be their correct values when I run the script.

However, I receive errors like this:

Net::SMTP::SSL>>> Net::SMTP::SSL(1.01)
Net::SMTP::SSL>>>   IO::Socket::SSL(1.30)
Net::SMTP::SSL>>>     IO::Socket::INET(1.31)
Net::SMTP::SSL>>>       IO::Socket(1.30_01)
Net::SMTP::SSL>>>         IO::Handle(1.27)
Net::SMTP::SSL>>>           Exporter(5.62)
Net::SMTP::SSL>>>   Net::Cmd(2.29)
Net::SMTP::SSL=GLOB(0x2065958)<<< 220 mx.google.com ESMTP y6sm320414mug.40
Net::SMTP::SSL=GLOB(0x2065958)>>> EHLO localhost.localdomain
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-mx.google.com at your service, [128.113.81.58]
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-SIZE 35651584
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-8BITMIME
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-AUTH LOGIN PLAIN
Net::SMTP::SSL=GLOB(0x2065958)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP::SSL=GLOB(0x2065958)<<< 250 PIPELINING
Authentication failed!

And yes, I am certain that all the values I am using are valid.

Any thoughts about this?

Install module : Authen-SASL to fix the problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.