http://qs321.pair.com?node_id=11117561

jfwell has asked for the wisdom of the Perl Monks concerning the following question:

Trying to send an email from Perl. Both programs I've tried to use end up with the same error message: ".../IO/Socket/SSL.pm:1177: global error: Undefined SSL object". If I understand the messages correctly it appears that in both cases Net::SMTPS sends information to IO::Socket::SSL which clearly SSL.pm doesn't like. Since I'm at the limit of what I know, I thought I would ask for any information I could get.

Program 1

use Email::Sender::Simple qw(sendmail); use Email::Sender::Transport::SMTPS; use Email::Simple (); use Email::Simple::Creator (); my $smtpserver = 'ddd.com'; my $smtpport = 587; my $smtpuser = 'xxx@ddd.com'; my $smtppassword = 'yyyyyy'; my $transport = Email::Sender::Transport::SMTPS->new({ host => $smtpserver, ssl => 'starttls', port => $smtpport, sasl_username => $smtpuser, sasl_password => $smtppassword, debug => 1, }); my $email = Email::Simple->create( header => [ To => 'xxx@ddd.com', From => 'xxx@ddd.com', Subject => 'Hi!', ], body => "This is my message\n", ); sendmail($email, { transport => $transport });

The debug flag returns the following information:

Net::SMTPS>>> Net::SMTPS(0.10) Net::SMTPS>>> IO::Socket::IP(0.39) Net::SMTPS>>> IO::Socket(1.40) Net::SMTPS>>> IO::Handle(1.40) Net::SMTPS>>> Exporter(5.74) Net::SMTPS>>> Net::SMTP(3.11) Net::SMTPS>>> Net::Cmd(3.11) Net::SMTPS=GLOB(0x556317f13e28)<<< 220-ddd.com ESMTP Exim 4.92 #2 Mon, + 01 Jun 2020 07:42:59 -0600 Net::SMTPS=GLOB(0x556317f13e28)<<< 220-We do not authorize the use of +this system to transport unsolicited, Net::SMTPS=GLOB(0x556317f13e28)<<< 220 and/or bulk e-mail. Net::SMTPS=GLOB(0x556317f13e28)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x556317f13e28)<<< 250-ddd.com Hello dsl-ip.fuse.net [ +ipaddr] Net::SMTPS=GLOB(0x556317f13e28)<<< 250-SIZE 52428800 Net::SMTPS=GLOB(0x556317f13e28)<<< 250-8BITMIME Net::SMTPS=GLOB(0x556317f13e28)<<< 250-PIPELINING Net::SMTPS=GLOB(0x556317f13e28)<<< 250-AUTH PLAIN LOGIN Net::SMTPS=GLOB(0x556317f13e28)<<< 250-STARTTLS Net::SMTPS=GLOB(0x556317f13e28)<<< 250 HELP Net::SMTPS=GLOB(0x556317f13e28)>>> STARTTLS Net::SMTPS=GLOB(0x556317f13e28)<<< 220 TLS go ahead DEBUG: .../IO/Socket/SSL.pm:1177: global error: Undefined SSL object Net::SMTPS=GLOB(0x556317f13e28)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x556317f13e28)<<< 250-ddd.com Hello dsl-ip.fuse.net [ +ipaddr] Net::SMTPS=GLOB(0x556317f13e28)<<< 250-SIZE 52428800 Net::SMTPS=GLOB(0x556317f13e28)<<< 250-8BITMIME Net::SMTPS=GLOB(0x556317f13e28)<<< 250-PIPELINING Net::SMTPS=GLOB(0x556317f13e28)<<< 250-AUTH PLAIN LOGIN Net::SMTPS=GLOB(0x556317f13e28)<<< 250 HELP Net::SMTPS=GLOB(0x556317f13e28)>>> AUTH PLAIN -stuff here- Net::SMTPS=GLOB(0x556317f13e28)<<< 535 Incorrect authentication data failed AUTH: Incorrect authentication data

Program 2 is:

use Net::SMTPS ; use MIME::Lite ; my $msg = MIME::Lite ->new ( From => 'xxx@ddd.com', To => 'xxx@ddd.com', Subject => 'Test Message', Data => 'This is a test', Type => 'text/html' ); my $USERNAME = 'xxx@ddd.com'; my $PASSWORD = 'yyyyyyyy'; my $smtps = Net::SMTPS->new("ddd.com", Port => 587, doSSL => 'starttl +s', Debug => 1, Debug_SSL => 3); $smtps->auth ( $USERNAME, $PASSWORD ) or die("Could not authenticate\n +"); $smtps->mail('xxx@ddd.com'); $smtps->to('xxx@ddd.com'); $smtps->data(); $smtps->datasend( $msg->as_string() ); $smtps->dataend(); $smtps->quit;

The debug flags return the following information:

Net::SMTPS>>> Net::SMTPS(0.10) Net::SMTPS>>> IO::Socket::IP(0.39) Net::SMTPS>>> IO::Socket(1.40) Net::SMTPS>>> IO::Handle(1.40) Net::SMTPS>>> Exporter(5.74) Net::SMTPS>>> Net::SMTP(3.11) Net::SMTPS>>> Net::Cmd(3.11) Net::SMTPS=GLOB(0x5609e794aac0)<<< 220-ddd.com ESMTP Exim 4.92 #2 Mon, + 01 Jun 2020 08:30:01 -0600 Net::SMTPS=GLOB(0x5609e794aac0)<<< 220-We do not authorize the use of +this system to transport unsolicited, Net::SMTPS=GLOB(0x5609e794aac0)<<< 220 and/or bulk e-mail. Net::SMTPS=GLOB(0x5609e794aac0)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-ddd.com Hello dsl-ip.fuse.net [ +ipaddr] Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-SIZE 52428800 Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-8BITMIME Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-PIPELINING Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-AUTH PLAIN LOGIN Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-STARTTLS Net::SMTPS=GLOB(0x5609e794aac0)<<< 250 HELP Net::SMTPS=GLOB(0x5609e794aac0)>>> STARTTLS Net::SMTPS=GLOB(0x5609e794aac0)<<< 220 TLS go ahead DEBUG: .../IO/Socket/SSL.pm:3010: new ctx 94600543851488 DEBUG: .../IO/Socket/SSL.pm:1620: start handshake DEBUG: .../IO/Socket/SSL.pm:1177: global error: Undefined SSL object DEBUG: .../IO/Socket/SSL.pm:787: ssl handshake not started DEBUG: .../IO/Socket/SSL.pm:832: not using SNI because hostname is unk +nown DEBUG: .../IO/Socket/SSL.pm:864: request OCSP stapling DEBUG: .../IO/Socket/SSL.pm:880: set socket to non-blocking to enforce + timeout=120 DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/SSL.pm:907: ssl handshake in progress DEBUG: .../IO/Socket/SSL.pm:917: waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/SSL.pm:937: socket ready, retrying connect DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/SSL.pm:907: ssl handshake in progress DEBUG: .../IO/Socket/SSL.pm:917: waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/SSL.pm:937: socket ready, retrying connect DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/SSL.pm:907: ssl handshake in progress DEBUG: .../IO/Socket/SSL.pm:917: waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/SSL.pm:937: socket ready, retrying connect DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/SSL.pm:907: ssl handshake in progress DEBUG: .../IO/Socket/SSL.pm:917: waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/SSL.pm:937: socket ready, retrying connect DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect DEBUG: .../IO/Socket/SSL.pm:2864: ok=1 [2] /C=GB/ST=Greater Manchester +/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority/ +C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RS +A Certification Authority DEBUG: .../IO/Socket/SSL.pm:2864: ok=1 [1] /C=GB/ST=Greater Manchester +/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority/ +C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Aut +hority DEBUG: .../IO/Socket/SSL.pm:2864: ok=1 [0] /C=US/ST=TX/L=Houston/O=cPa +nel, Inc./CN=cPanel, Inc. Certification Authority/CN=box826.bluehost. +com DEBUG: .../IO/Socket/SSL.pm:2911: did not get stapled OCSP response DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/SSL.pm:907: ssl handshake in progress DEBUG: .../IO/Socket/SSL.pm:917: waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/SSL.pm:937: socket ready, retrying connect DEBUG: .../IO/Socket/SSL.pm:894: call Net::SSLeay::connect DEBUG: .../IO/Socket/SSL.pm:897: done Net::SSLeay::connect -> 1 DEBUG: .../IO/Socket/SSL.pm:952: ssl handshake done Net::SMTPS=GLOB(0x5609e794aac0)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-ddd.com Hello dsl-ip.fuse.net [ +ipaddr] Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-SIZE 52428800 Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-8BITMIME Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-PIPELINING Net::SMTPS=GLOB(0x5609e794aac0)<<< 250-AUTH PLAIN LOGIN Net::SMTPS=GLOB(0x5609e794aac0)<<< 250 HELP Net::SMTPS=GLOB(0x5609e794aac0)>>> AUTH PLAIN -stuff here Net::SMTPS=GLOB(0x5609e794aac0)<<< 535 Incorrect authentication data Could not authenticate

It has been a long time since I did any programming and I am not sure how to proceed to fix this. Any thoughts welcome and Thanks

Replies are listed 'Best First'.
Re: sending email with starttls not working
by jfwell (Initiate) on Jun 02, 2020 at 13:45 UTC

    Ok the short version here is that the problem is solved. Both scripts now work. The solution (which doesn't make a whole lot of sense to me) was to change authentication values - namely the smtp server to connect to. Not sure what is going on with my provider - all my other devices continued to work with the values I was using in these scripts.

    That said, even though the scripts work they both still get the error ".../IO/Socket/SSL.pm:1177: global error: Undefined SSL object" which may be of interest to someone.

    So thank you perlfan and nysus for your help it made me question some assumptions that lead to the solution. (By the way perlfan your script now works for me as well.)

Re: sending email with starttls not working
by perlfan (Vicar) on Jun 01, 2020 at 18:39 UTC
    This works for me, but I also don't have issues with my openssl or IO::Socket::SSL. I'd look there first.
    my $config = Config::Tiny->new(); $config = Config::Tiny->read($config_file); my $transport = Email::Sender::Transport::SMTP::TLS->new( host => $config->{email}->{smtp_host}, port => 587, # defaults to TLS if not set username => 'bgates@microsoft.com', password => '66Fc1eb207d4380', helo => 'HELO', ); my $message = Email::Simple->create( header => [ From => 'bgates@microsoft.com', To => $to, Subject => $subject, ], body => $content, );
Re: sending email with starttls not working
by nysus (Parson) on Jun 01, 2020 at 19:58 UTC

    The module you are using is deprecated. See note on Email::Sender::Transport::SMTPS. It says to use Email::Sender::Transport::SMTP instead.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Re: sending email with starttls not working
by nysus (Parson) on Jun 01, 2020 at 19:47 UTC

    Are you on a Mac? There are known issues with ssl on macs. They are fixable, though.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      Actually, from your debug output, it looks like you've got 535 Incorrect authentication data which would indicate it doesn't like the user/pass you are using.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks