1
votes

None of my hosts have any higher email modules, so I'd prefer to get this working without additional modules.

I've tried using google smtp servers (which i got working with \sendmail in XAMPP but never through Net::SMTP), I've tried secureserver.net smtp servers. with and without SSL, with and without Hello lines, port 465 or 25. Tried running from my local XAMPP server disabled all firewalls, tried running it remotely on goDaddy server.

Seems to be timing out and 'smtp failed'. never getting to '...' even without the unless($smtp) test. failing to get past auth, but since 'smtp failed' is being fired i assume its a problem with how i am forming the initial declaration of the object? Though I've tried this in several different ways and I'm not getting any actual server errors.

my $smtp = Net::SMTP->new($smtpserver,
    SSL => 1,                   
    Timeout => 60,
    Port => $smtpport,  # tried 25 and 465
    Debug => 1
);
    unless($smtp) { #tried with and without this
        print "smtp failed<br>[".$!."]<br>and<br>".$IO::Socket::SSL::SSL_ERROR;
    }
$smtp->auth($smtpuser, $smtppassword);    #nothing under this line is done
$smtp->mail($smtpuser);            #but i have checked and double checked the data
$smtp->recipient($recipi);         #pointed to several email addys but never arrive
$smtp->data();
$smtp->datasend("From: $smtpuser");
$smtp->datasend("To: $recipi");
$smtp->datasend("Subject: test mail ver six sm loc 12"); 
$smtp->datasend("\n");
$smtp->datasend("blah blah");
$smtp->dataend();
$smtp->quit;
print"...";  #never gets printed

Any suggestions welcome, the only thing I've thought of and not tried is including the authentication in the initial object deceleration, i can find no where that shows how to do that.

edit; added $! and $IO::Socket::SSL::SSL_ERROR Steffen suggested the result is $! = [Bad file descriptor] and $IO::Socket::SSL::SSL_ERROR returns nothing.

2
Please include $! and $IO::Socket::SSL::SSL_ERROR in your print "smtp failed<br>" to get details of the error. And since youve already used Debug` please include the actual debug output in your question. Also SSL =>1 makes only sense with port 465, for ports 25 and 587 you need to use $smtp->starttls() instead.Steffen Ullrich
Updated my post with your suggestion, port 25 without ssl times out, [A connection attempt failed because the connected party did not properly respond] on both servers. unsure how to use starttls, what args do i () into this?jobeSW
"port 25 without ssl times out,..." - this suggests that either there is no service on this port on the target host or that your connection is blocked by a firewall (which seems to be not unusual in GoDaddy setups to prevent spammers). If the initial connection already fails starttls will not help. As to how to use starttls please refer to the documentation of Net::SMTP.Steffen Ullrich
thanks, i skimmed IO::Socket::SSL docs so i think i understand starttls a bit better. On port 465 with ssl=>1 i get $![Bad file descriptor] i'm guessing that's a problem with the initial object setup?jobeSW
Yes, I would say that the initial TCP connection fails already.Steffen Ullrich

2 Answers

1
votes

Try the following code (it requires Authen::SASL module which might be not part of your setup)

use strict;
use warnings;
use utf8;

use Net::SMTP 3.0;
use Authen::SASL qw(Perl);

my $sender = my $user = '[email protected]';
my $password = 'your_password';
my $receiver = '[email protected]';

my $smtp = Net::SMTP->new(
    'smtp.gmail.com',
    SSL=>1,
    Timeout => 20,
    Debug   => 1,
);

die "Initialization failed: $!" if !defined $smtp;

print "Trying to authenticate..";
$smtp->auth( $user, $password) or die "could not authenticate\n";

my $header = 
"To: $receiver
From: $sender
Content-Type: text/html
Subject: Testing Net::SMTP

";

my $body = "
The <i>body</i> of the <b>email</b> Net-SMTP example
";

$smtp->mail( $sender );
$smtp->to( $receiver );
$smtp->data();
$smtp->datasend( $header );
$smtp->datasend( $body );
$smtp->datasend( '' );
$smtp->dataend();
$smtp->quit();
0
votes

I use this code:

use Net::SMTP::SSL;

my $smtp = Net::SMTP::SSL->new(
    Host=>$host,
    Hello=>$host,
    Port=>465,
    Debug=>1
);

$smtp->auth($smtp_user, $smtp_pass);

# ...