0

I have been using Net::SMTP::TLS for my web application to send password reset emails using Google email for years.

my $smtp = Net::SMTP::TLS->new(email-smtp.us-east-1.amazonaws.com,
                                    Hello => ,
                                    Port => 587,
                                    Timeout => 10,
                                    Debug   => 0,
                                    User => from-user-no-reply@example.com,
                                    Password => password123,
#                                   NoTLS => !$gsmtpssl,
#                                   Blocking => $blocking,
                                    ) or $c = 1;

            print "TLS returned: $c,$smtp\n";

I have changed to Amazon's Simple Email Service. As documented in the AWS documentation, the email address that I'm using to send has been verified by Amazon SES. In the AWS console, I had to create SMTP credentials which were encrypted. Correct me if I am wrong, in order to send emails from a verified email address in AWS Simple Email Service, I need a SMTP username, SMTP password, SMTP server name and SMTP port. Which I was able to obtain.

       smtpuser abc
       smtppassword 123456 
       email-smtp.us-east-1.amazonaws.com

But I want to send emails using the from-user-no-reply@example.com and the smtp credentials provided to me by Amazon and it's not working.

#!/usr/bin/perl -w 
use strict;
use Data::Dumper;
use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
   'email-smtp.us-east-1.amazonaws.com',
   Hello   =>      'World',
   Port    =>      587, #redundant
   User    =>      'abc',
   Password=>      '123456');
print Dumper($mailer);
$mailer->mail('from-user-no-reply@example.com');
$mailer->to('whoever@helloworld.com');
$mailer->data;
$mailer->datasend("Sent thru TLS!");
$mailer->dataend;
$mailer->quit;
BioRod
  • 303
  • 4
  • 13
  • 1
    https://idownvotedbecau.se/itsnotworking/ - "it's not working." is not a usable error description. Please use the `Debug` setting of Net::SMTP::TLS to debug SMTP level problems and use `perl -MIO::Socket::SSL=debug4 app.pl` to debug TLS level problems. Also, check the actual errors of the functions you call instead of just continuing. – Steffen Ullrich Feb 07 '20 at 21:47
  • 1
    Also note that Net::SMTP::TLS is unmaintained since 14! years. The functionality you need is included for a long time in Net::SMTP so please use this instead, it works almost the same. – Steffen Ullrich Feb 07 '20 at 21:50

1 Answers1

1

Perl Net::SMTP - STARTTLS and AUTH via port 587 (msa)

Use Net::SMTP. Its versions above 3.00 support STARTTLS SMTP command.

#!/usr/bin/perl
use strict;
use warnings;

use Net::SMTP;
my $user=  'abc';
my $pass=  '123456';
my $mailer = new Net::SMTP(
   'email-smtp.us-east-1.amazonaws.com',
   Port    =>   587,
   Debug   =>  1, # needed only during debugging
);
if( $mailer ) {
  my $ok;
  $mailer->starttls() &&
  $mailer->auth( $user, $pass) &&
  $mailer->mail('from-user-no-reply@example.com') &&
  $mailer->to('whoever@helloworld.com') &&
  $mailer->data() &&
  $mailer->datasend(<<"END") &&
From: from-user-no-reply@example.com
To:  whoever@helloworld.com
Subject: Delivery Test

Delivery test.
END
  $mailer->dataend &&
  $ok = 1;
  $mailer->quit;
}
AnFi
  • 6,103
  • 1
  • 14
  • 27