Roger Creasy
Roger Creasy

Reputation: 1529

Perl SMTP auth fails when password is passed via variable

I have several hundred Perl scripts that send email via gmail SMTP. All are, and have been working fine for a couple of years with the gmail password hard-coded.

To simplify password changes (and for security), I want to move the password to an env var, and pull that into the perl scripts. I am using the code below.

my $smtp = Net::SMTP::SSL->new('smtp.gmail.com', Port => 465);
my $passwd = $ENV{'PASSWD'}; # I added this line
$smtp->auth('[email protected]', $passwd); # I replaced 'theHardCodedPassWord' with $passwd

The same method works in a non-smtp scenario -- I pull info from an env var and use it.

What am I doing wrong?

Upvotes: 0

Views: 122

Answers (1)

Dave Cross
Dave Cross

Reputation: 69314

Two obvious debugging approaches:

  • Print the values of $ENV{PASSWD} and $passwd before the call to auth().
  • Turn on debug output in the Net::SMTP::SSL object (add Debug => 1 to the call to new()).

A few other points:

  • The documentation for Net::SMTP::SSL is pretty clear that the module is deprecated and should no longer be used. It says that Net::SMTP now has built-in support for SSL connections.
  • Net::SMTP seems to be a rather low-level approach to this problem. Have you considered Email::Send::Gmail? I've even had success sending email through GMail with Email::Sender::Simple.
  • I know that GMail recently hardened their security around using their SMTP servers from external apps. There's more information about this change on the Google support site.

Upvotes: 1

Related Questions