Send mail via Gmail using Perl

I have this perl script:

#!/usr/bin/perl

use Net::SMTP::TLS;

my $file="/var/www/myweb/textfile.txt";

my $smtp = new Net::SMTP::TLS(
'smtp.gmail.com',
    Hello => 'smtp.gmail.com',
    Port => 587,
    User => 'mymail@gmail.com',
    Password => 'mypassword',
);

$smtp->mail('mymail@gmail.com');
$smtp->to('destinationmail@hotmail.com');
$smtp->data();
$smtp->datasend("Subject: Subject of mail \n");
$smtp->datasend("\n");

#make sure file exists
if (-e $file) {
    $smtp->datasend("body of the mail");
    #read the file one line at a time
    open( RFILE, "<$file" )||print "could not open file";
    while (my $line  = <RFILE>){
            $smtp->datasend("$line");
    }
    close(RFILE) || print "could not close file";
}
else {
    #print "did not find the report $file ";
    exit 1;
}
#End the message.
$smtp->dataend();
#Close the connection to your server.
$smtp->quit();

This script open the textfile.txt file and put its contents in the body of the email message. Since yesterday, this script worked perfectly on 4 different Linux computers. Now it returns this message:

Failed to start TLS: SSL connection attempt failed due to handshake problems Error: 1409442E: SSL routines: SSL3_READ_BYTES: warning protocol tlsv1 version on scriptname.pl 7

I did not find any documentation of any changes to the Gmail SMTP service. How can i do

thank

+4
source share
3 answers

, script. Net:: SMTP:: TLS MIME:: Lite

#!/usr/bin/perl
use MIME::Lite;
use Net::SMTPS;

my $file="/var/www/myweb/myfile.txt";
open(FILE, $file) or die "Can't read file 'filename' [$!]\n";  
$document = <FILE>; 
close (FILE);  
my $msg = MIME::Lite ->new (  
From => 'sender@hotmail.com',
To => 'recipient@hotmail.com',
Subject => 'mail subject',  
Data => qq{
<body>
Text message body HTML format. <p> $document </p>
</body>
},
Type => 'text/html; charset=UTF-8'
);  
my $USERNAME = 'sender@hotmail.com';
my $PASSWORD = 'password'; 

my $smtps = Net::SMTPS->new("smtp.live.com", Port => 587, doSSL=> 'starttls', SSL_version=>'TLSv1');

$smtps->auth ( $USERNAME, $PASSWORD ) or DIE("Could not authenticate with mail.\n");

$smtps ->mail('sender@hotmail.com');  
$smtps->to('recipient@hotmail.com');
$smtps->data(); 
$smtps->datasend( $msg->as_string() );  
$smtps->dataend();  
$smtps->quit;

Outlook.com GMail.

!

0

Net::SMTP::TLS 2006 , IO:: Socket:: SSL ( - ) (- SSL 3.0). Net:: SMTP:: TLS IO:: Socket:: SSL ( , , ).

, , Net:: SMTP:: TLS, IO:: Socket:: SSL. - . - SSL 3.0, gmail.

: Net:: SMTP:: TLS Net:: SMTP ( ). 3.x( 2014) TLS IPv6 ( IO:: Socket:: SSL). perl 5.22+. , Net:: SSLGlue:: SSL, SSL Net:: SMTP.

+4

Go to https://www.google.com/settings/security/lesssecureapps and make sure it’s “Enable”

0
source

All Articles