There are some extra bits in there that I added to try to see what's going on - ignore those. I just want the mail part to work.
Code: Select all
#!/usr/bin/perl -w
use feature qw(say);
use strict;
use warnings;
use Net::SMTPS;
use LWP::UserAgent 6;
use Data::Dumper;
use utf8;
use Authen::SASL qw(Perl);
my $ua = LWP::UserAgent->new;
$ua->ssl_opts( SSL_hostname => '' );
my $x = $ua->get("https://(servername)/");
print Dumper($x);
my $smtp = Net::SMTPS->new(
'smtp.(servername)',
Port => 587,
Timeout => 20,
Debug => 1,
doSSL => 'starttls',
SSL => 1,
SSL_version=>'TLSv1',
);
die "Initialization failed: $!" if !defined $smtp;
my $sender = my $user = '(emailaddress)';
my $password = '(pw)';
say "Trying to authenticate..";
$smtp->auth( $user, $password, 'LOGIN' ) or die "could not authenticate\n";
my $receiver = '(emailaddress)';
$smtp->mail( $sender );
$smtp->to( $receiver );
$smtp->data();
$smtp->datasend( "To: $receiver\n" );
$smtp->datasend( "From: $sender\n" );
$smtp->datasend( "Content-Type: text/html\n" );
$smtp->datasend( "Subject: Testing Net::SMTPS" );
$smtp->datasend( "\n" );
$smtp->datasend( 'The body of the email' );
$smtp->dataend();
$smtp->quit();
say "Done.";
Code: Select all
Net::SMTPS>>> Net::SMTPS(0.09)
Net::SMTPS>>> IO::Socket::IP(0.37)
Net::SMTPS>>> IO::Socket(1.38)
Net::SMTPS>>> IO::Handle(1.36)
Net::SMTPS>>> Exporter(5.72)
Net::SMTPS>>> Net::SMTP(3.08_01)
Net::SMTPS>>> Net::Cmd(3.08_01)
Net::SMTPS=GLOB(0x1676198)<<< 220 serverdef.(servername)
Net::SMTPS=GLOB(0x1676198)>>> EHLO localhost.localdomain
Net::SMTPS=GLOB(0x1676198)<<< 250-serverdef.(servername)
Net::SMTPS=GLOB(0x1676198)<<< 250-PIPELINING
Net::SMTPS=GLOB(0x1676198)<<< 250-SIZE 10240000
Net::SMTPS=GLOB(0x1676198)<<< 250-VRFY
Net::SMTPS=GLOB(0x1676198)<<< 250-ETRN
Net::SMTPS=GLOB(0x1676198)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x1676198)<<< 250-ENHANCEDSTATUSCODES
Net::SMTPS=GLOB(0x1676198)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x1676198)<<< 250-DSN
Net::SMTPS=GLOB(0x1676198)<<< 250 SMTPUTF8
Net::SMTPS=GLOB(0x1676198)>>> STARTTLS
Net::SMTPS=GLOB(0x1676198)<<< 220 2.0.0 Ready to start TLS
DEBUG: .../IO/Socket/SSL.pm:792: local error: SSL connect attempt failed error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
DEBUG: .../IO/Socket/SSL.pm:795: fatal SSL error: SSL connect attempt failed error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

