I was under the impression that the SSL support in Net::SMTP had made it redundant. However, I do know that Net::SMTPS works for my app and the documentation for using Net::SMTP only for TLS connection is sorely lacking.
BTW, the current Net:SMTP code looks like:
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::SSL qw(debug3);
use Net::SMTP;
use CGI::Carp qw(fatalsToBrowser);
use English '-no_match_vars';
our @ARGV = ( 'mygmail@gmail.com', 'mypassword', 'touser@forumsoftware
+.com', 'mygmail@gmail.com' );
my $body = "Test message";
my $headers = "Content-Type: text/plain\r\n\r\n";
my $smtp_server = 'smtp.gmail.com';
my $port = 587;
my $mailer = new Net::SMTP(
$smtp_server,
Hello => 'host.domain.net',
Port => $port,
Debug => 1,
User => $ARGV[0],
Password => $ARGV[1],
) || die "Unable to create Net::SMTP object. Server: '$smtp_server
+', port '$port'\n\n" . $OS_ERROR;
$mailer->auth($ARGV[0], $ARGV[1]);
$mailer->mail($ARGV[3]);
$mailer->to($ARGV[2]);
$mailer->data();
$mailer->datasend("Subject: Net::SMTP test\r\n\r\n" . $headers . $body
+);
$mailer->dataend;
$mailer->quit;
print "Content-type: text/html\n\n" or croak 'cannot print line1';
print "Complete";
exit();
gets this from the debug trace:
Net::SMTP>>> Net::SMTP(2.31)
Net::SMTP>>> Net::Cmd(2.29)
Net::SMTP>>> Exporter(5.58)
Net::SMTP>>> IO::Socket::INET(1.29)
Net::SMTP>>> IO::Socket(1.29)
Net::SMTP>>> IO::Handle(1.25)
Net::SMTP=GLOB(0x97fc844)<<< 220 smtp.gmail.com ESMTP 89sm4313614pfi.2
+ - gsmtp
Net::SMTP=GLOB(0x97fc844)>>> EHLO host.domain.net
Net::SMTP=GLOB(0x97fc844)<<< 250-smtp.gmail.com at your service, [67.2
+22.16.122]
Net::SMTP=GLOB(0x97fc844)<<< 250-SIZE 35882577
Net::SMTP=GLOB(0x97fc844)<<< 250-8BITMIME
Net::SMTP=GLOB(0x97fc844)<<< 250-STARTTLS
Net::SMTP=GLOB(0x97fc844)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP=GLOB(0x97fc844)<<< 250-PIPELINING
Net::SMTP=GLOB(0x97fc844)<<< 250-CHUNKING
Net::SMTP=GLOB(0x97fc844)<<< 250 SMTPUTF8
Net::SMTP=GLOB(0x97fc844)>>> MAIL FROM:<mygmail@gmail.com>
Net::SMTP=GLOB(0x97fc844)<<< 530 5.7.0 Must issue a STARTTLS command f
+irst. 89sm4313614pfi.2 - gsmtp
I think this indicates that STARTTLS started, but something happened.
More: The Net::SMTP on my production server is 2.31. Therefore Net::SMTPS it is. That said, it would be nice if someone would put together a tutorial explaining all this for people suffering through trying to get this to work as advertised. |