Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Net::SMTP::SSL ACK!!

by Dandello (Monk)
on Feb 02, 2016 at 16:45 UTC ( [id://1154286]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Net::SMTP::SSL ACK!!
in thread Net::SMTP::SSL ACK!!

#!/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.

Replies are listed 'Best First'.
Re^4: Net::SMTP::SSL ACK!!
by hippo (Bishop) on Feb 02, 2016 at 17:48 UTC
    Yes, I know Net::SMTPS is also old and deprecated

    AFAICT Net::SMTPS is neither old nor deprecated. Perhaps you are confusing it with something else?

      I was under the impression that the SSL support in Net::SMTP had made it redundant. However, I do know that Net::SMTPS works for my app and the documentation for using Net::SMTP only for TLS connection is sorely lacking.

      BTW, the current Net:SMTP code looks like:

      #!/usr/bin/perl use strict; use warnings; use IO::Socket::SSL qw(debug3); use Net::SMTP; use CGI::Carp qw(fatalsToBrowser); use English '-no_match_vars'; our @ARGV = ( 'mygmail@gmail.com', 'mypassword', 'touser@forumsoftware +.com', 'mygmail@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 $mailer = new Net::SMTP( $smtp_server, Hello => 'host.domain.net', Port => $port, Debug => 1, User => $ARGV[0], Password => $ARGV[1], ) || die "Unable to create Net::SMTP object. Server: '$smtp_server +', 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: Net::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();

      gets this from the debug trace:

      Net::SMTP>>> Net::SMTP(2.31) Net::SMTP>>> Net::Cmd(2.29) Net::SMTP>>> Exporter(5.58) Net::SMTP>>> IO::Socket::INET(1.29) Net::SMTP>>> IO::Socket(1.29) Net::SMTP>>> IO::Handle(1.25) Net::SMTP=GLOB(0x97fc844)<<< 220 smtp.gmail.com ESMTP 89sm4313614pfi.2 + - gsmtp Net::SMTP=GLOB(0x97fc844)>>> EHLO host.domain.net Net::SMTP=GLOB(0x97fc844)<<< 250-smtp.gmail.com at your service, [67.2 +22.16.122] Net::SMTP=GLOB(0x97fc844)<<< 250-SIZE 35882577 Net::SMTP=GLOB(0x97fc844)<<< 250-8BITMIME Net::SMTP=GLOB(0x97fc844)<<< 250-STARTTLS Net::SMTP=GLOB(0x97fc844)<<< 250-ENHANCEDSTATUSCODES Net::SMTP=GLOB(0x97fc844)<<< 250-PIPELINING Net::SMTP=GLOB(0x97fc844)<<< 250-CHUNKING Net::SMTP=GLOB(0x97fc844)<<< 250 SMTPUTF8 Net::SMTP=GLOB(0x97fc844)>>> MAIL FROM:<mygmail@gmail.com> Net::SMTP=GLOB(0x97fc844)<<< 530 5.7.0 Must issue a STARTTLS command f +irst. 89sm4313614pfi.2 - gsmtp

      I think this indicates that STARTTLS started, but something happened.

      More: The Net::SMTP on my production server is 2.31. Therefore Net::SMTPS it is. That said, it would be nice if someone would put together a tutorial explaining all this for people suffering through trying to get this to work as advertised.

Re^4: Net::SMTP::SSL ACK!!
by noxxi (Pilgrim) on Feb 02, 2016 at 23:58 UTC

    > 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.

    I think that if you are still using a system with 5.8.8 then you will probably run into more problems, like missing support for newer TLS versions etc. Apart from that current IO::Socket::SSL should still run with 5.8.8 but you have to install it and probably even newer versions of Net::SSLeay. Trying to enforce use of the very old version 1.79 will not work because it needs features of the newer versions.

    I guess your problems are more related to the use of very old and for years unsupported code and you better should upgrade instead of trying to work around all these problems.

      My home Perl workspace is currently on ActiveState 5.16.3 The production server is using cPanel on VPS - and depending on the OS configuration on the server, cPanel STILL ships with Perl 5.8.8. (And I believe Plesk does the same.) What I'm writing has to work at least adequately on 5.8.8 and up because this code is going into an app that has to run on 5.8.8 and up.

      The version of cPanel that ships with Perl 5.8.8 also ships with a 3rd-party install of Perl 5.14 - but the problem there is that you can't update the installed modules in the 3rd-party install. (Although I may have figured out a way to work around that annoyance - needs some testing, though, and it doesn't help other users using installing the app who are on all sorts of different servers.)

      So Net::SMTPS works for this problem. Hopefully by the time it stops working, cPanel will be shipping with a more current version of Perl.

        depending on the OS configuration on the server, cPanel STILL ships with Perl 5.8.8.

        A cursory read of the cPanel documentation shows that not to be the case. Rather it is bundled with 5.14.4. If you use the vendor perl rather than the cPanel-bundled perl that is your (or your hoster's) choice and you cannot blame cPanel for it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154286]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found