Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Email::Send::SMTP::Gmail issue

by flieckster (Scribe)
on May 03, 2017 at 21:21 UTC ( #1189460=perlquestion: print w/replies, xml ) Need Help??

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

#!/usr/bin/env perl use strict; use warnings; use File::Find; use File::Copy; use Mail::Sender; use Net::SMTP; use Email::Send::SMTP::Gmail; my $user = '####@####.#'; my $pass = '########'; my ($mail,$error)=Email::Send::SMTP::Gmail->new( -smtp=>' +m', -login=>$user, -pass=>$pass, -port=> '25', -verbose=>1, -debug=> 1,); my $subject = "Folder Counts"; my $to = ''; $mail->send(-to=>"$to",-from=>"$to", -subject=>"$subject"); $mail->bye;
so the above code works on my one system just fine, i and loaded all the modules that are required for this simple script, yet when i run it i get the following error.
Connecting to using tls with LOGIN on port 25 and timeo +ut of 60 Net::SMTPS>>> Net::SMTPS(0.06) Net::SMTPS>>> IO::Socket::IP(0.37) Net::SMTPS>>> IO::Socket(1.38) Net::SMTPS>>> IO::Handle(1.36) Net::SMTPS>>> Exporter(5.72) Net::SMTPS>>> Net::SMTP(3.10) Net::SMTPS>>> Net::Cmd(3.10) Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 220 ESMTP s28sm13216 +4qts.35 - gsmtp Net::SMTPS=GLOB(0x7ff7c22e6fe0)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< at your service, + [] Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 250-SIZE 35882577 Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 250-8BITMIME Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 250-STARTTLS Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 250-PIPELINING Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 250-CHUNKING Net::SMTPS=GLOB(0x7ff7c22e6fe0)<<< 250 SMTPUTF8 Net::SMTPS=GLOB(0x7ff7c22e6fe0)>>> my favorite: LOGIN Authentication (SMTP) failed Can't locate object method "send" via package "-1" (perhaps you forgot + to load "-1"?)
Where is it getting "my Favorite:" from? thanks all.

Replies are listed 'Best First'.
Re: Email::Send::SMTP::Gmail issue
by zentara (Archbishop) on May 04, 2017 at 14:35 UTC
    Hi, something seems wrong with using using port 25 for TLS(SSL) connection. You can google for it yourself, but the port used for GMAIL SSL is port 465 or 587. You seem to be trying to connect to the standard mail port, and authentication fails.

    Here is a simple script to show you how a SSL connection is done, I know this works, but it's a different module.

    #!/usr/bin/perl use warnings; use strict; use Net::SMTP::SSL; + # Implements the same API as Net::SMTP, but uses IO::Socket::SSL for i +ts # network operations. Due to the nature of "Net::SMTP"'s "new" method, + it # is not overridden to make use of a default port for the SMTPS servic +e. # Perhaps future versions will be smart like that. Port 465 is usually + # what you want, and it's not a pain to specify that. my $user = ''; my $pass = 'yeah_for_google'; #$server = 'your-smtp-server'; my $server = ''; my $to = ''; my $from_email = ''; my $subject = 'smtp-ssl-auth test'; my $smtps = Net::SMTP::SSL->new($server, Port => 465, DEBUG => 1, ) or warn "$!\n"; # I hust lucked out and this worked defined ($smtps->auth($user, $pass)) or die "Can't authenticate: $!\n"; $smtps->mail("$from_email\n"); $smtps->to("$to\n"); $smtps->data(); $smtps->datasend("From: $user\n"); $smtps->datasend("To: $to\n"); $smtps->datasend("Subject: $subject\n"); $smtps->datasend("Reply-To: $from_email\n"); $smtps->datasend("MIME-Version: 1.0\n"); $smtps->datasend("Content-Type: text/plain\n"); $smtps->datasend("\n"); $smtps->datasend("This will be the body of the message.\n"); $smtps->datasend("\n--\nVery Official Looking .sig here\n"); $smtps->datasend("\n"); $smtps->dataend(); #$smtps->quit(); print "done\n"; #You can alternatively just put everything in the argument to $smtp->d +ata(), #and forget about datasend() and dataend();

    I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Email::Send::SMTP::Gmail issue
by stevieb (Canon) on May 03, 2017 at 21:27 UTC

    Appears as though authentication is failing, which is resulting in -1 being placed into the $mail variable instead of the actual object.

    Try putting this immediately after the attempted object instantiation:

    die $error if $mail == -1;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1189460]
Approved by 1nickt
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-05-18 12:07 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (70 votes). Check out past polls.