#!/usr/bin/perl
use strict;
use warnings;
use Net::SMTPS;
use CGI::Carp qw(fatalsToBrowser);
use English '-no_match_vars';
our @ARGV = ( 'me_at@gmail.com', 'mypassword', 'tosombody@forumsoftwar
+e.com', 'me_at@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 $ssl = 'starttls'; # 'ssl' / 'starttls' / undef
my $mailer = new Net::SMTPS(
$smtp_server,
Hello => 'host.mydomain.net',
Port => $port,
Debug => 1,
doSSL => $ssl,
) || die "Unable to create Net::SMTPS object. Server: '$smtp_serve
+r', 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: 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();
Okay - the above works (and it's not Net::SMTP::TLS). Yes, I know Net::SMTPS is also old and deprecated BUT I found another complication last night. CPanel still ships with Perl 5.8.8 so my code has to work with Perl 5.8.8
Another annoyance - The docs for Net::SMTP 3.03 say this:
B<Port> - port to connect to.
Default - 25 for plain SMTP and 465 for immediate SSL.
B<SSL> - If the connection should be done from start with SSL, contrar
+y to later
upgrade with C<starttls>.
You can use SSL arguments as documented in L<IO::Socket::SSL>, but it
+will
usually use the right arguments already.
But that requires at least IO::Socket::SSL 2.007 and that is well above the version 1.79 that Perl 5.8.8 seems to support. Or at least above the version that I can get CPanel to install.
So, any hints on how to explicitly tell Net::SMTP 3.03 that it's supposed to tell IO::Socket::SSL 1.79 to start starttls.