Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Problem using Gmail Send

by IvanH (Novice)
on Jul 19, 2014 at 22:36 UTC ( #1094329=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I have some, but limited, experience with PERL. I am trying use Email::Send::SMTP::Gmail to send emails. I tried using the sample code provided with the module but can't get it to work. My OS is Windows 8.1, 64 bit. Here is the code I used (but with my real password:

use strict; use warnings; use Email::Send::SMTP::Gmail; my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com', -login=>'IHipschman@gmail.com' +, -pass=>'mypassword'); $mail->send(-to=>'IHipschman@yahoo.com', -subject=>'Hello!', -body=>'Just testing it<br>Bye!',-contenttype=>'text/html' +); $mail->bye;

The response I receive is:

C:\Users\Ivan\Documents\BSA\EMAIL\GmailSend>perl tryitmodified.pl Could not connect to SMTP server Can't call method "send" without a package or object reference at tryi +tmodified. pl line 8.
.

Can anyone suggest what the problem is? I have tried running from an administrator level command prompt and turning off the Windows firewall.

Thanks

Replies are listed 'Best First'.
Re: Problem using Gmail Send
by kcott (Bishop) on Jul 20, 2014 at 05:13 UTC

    G'day IvanH,

    As ++roboticus has pointed out, your core problem is the constructor (new()) failing. Here's some troubleshooting tips.

    • Add "-debug => 1" to new()'s argument list.
    • Check that Email::Send::SMTP::Gmail's default for -smtp (i.e. smtp.gmail.com) is valid for you.
    • Check spelling of -login value.
    • Check spelling of -pass value (i.e. "my real password").
    • Check that the password you're using doesn't have special characters (e.g. '$' and '@') that haven't been escaped.
    • Always check the return value of new() (both while debugging and in production code). If $mail is not a Email::Send::SMTP::Gmail object, provide appropriate feedback and exit your script gracefully.

    [The following is not documented as part of the published API, so don't rely on it remaining the same in future versions; however, looking at the latest (v0.85) source code, $mail with have a value of -1 if connection to the SMTP server failed.]

    -- Ken

Re: Problem using Gmail Send
by roboticus (Chancellor) on Jul 19, 2014 at 22:54 UTC

    IvanH:

    It means that Email::Send::SMTP::Gmail->new() failed somehow and didn't create a valid object for the $mail variable. I don't see anything obvious in the Email::Send::SMTP::Gmail docs about how to do diagnostics, so you may need to look over the source code to see why it may fail, or look at the related classes (e.g. Email::Send::SMTP) for diagnostic information.

    If you're using SMTP, you might consider running a telnet session to gmail to see if you can connect to the server and log in properly with the credentials you're using.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Problem using Gmail Send
by tbone654 (Beadle) on Jul 20, 2014 at 14:04 UTC
    Add these lines
    -layer=> 'ssl', -port=> 465, -debug=> 1, You will get similar if it works: Connecting to smtp.gmail.com using ssl with LOGIN Net::SMTPS>>> Net::SMTPS(0.03) Net::SMTPS>>> IO::Socket::INET(1.31) Net::SMTPS>>> IO::Socket(1.32) Net::SMTPS>>> IO::Handle(1.31) Net::SMTPS>>> Exporter(5.64_03) Net::SMTPS>>> Net::SMTP(2.31) Net::SMTPS>>> Net::Cmd(2.29) Net::SMTPS=GLOB(0x6003e5128)<<< 220 mx.google.com ESMTP b67sm22450316y +hc.16 - gsmtp Net::SMTPS=GLOB(0x6003e5128)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x6003e5128)<<< 250-mx.google.com at your service, [99 +.189.126.205] Net::SMTPS=GLOB(0x6003e5128)<<< 250-SIZE 35882577 Net::SMTPS=GLOB(0x6003e5128)<<< 250-8BITMIME Net::SMTPS=GLOB(0x6003e5128)<<< 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PL +AIN-CLIENTTOKEN Net::SMTPS=GLOB(0x6003e5128)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x6003e5128)<<< 250 CHUNKING Net::SMTPS=GLOB(0x6003e5128)>>> AUTH LOGIN Net::SMTPS=GLOB(0x6003e5128)<<< 334 VXNlcm5hbWU6 Net::SMTPS=GLOB(0x6003e5128)>>> dGN4bmllbWFuQGdtYWlsLmNvbQ== Net::SMTPS=GLOB(0x6003e5128)<<< 334 UGFzc3dvcmQ6 Net::SMTPS=GLOB(0x6003e5128)>>> bGE1dmVnYTU= Net::SMTPS=GLOB(0x6003e5128)<<< 235 2.7.0 Accepted Net::SMTPS=GLOB(0x6003e5128)>>> MAIL FROM:<mail@gmail.com> Net::SMTPS=GLOB(0x6003e5128)<<< 250 2.1.0 OK b67sm22450316yhc.16 - gsm +tp Net::SMTPS=GLOB(0x6003e5128)>>> RCPT TO:<mail@xxx.com> Net::SMTPS=GLOB(0x6003e5128)<<< 250 2.1.5 OK b67sm22450316yhc.16 - gsm +tp Net::SMTPS=GLOB(0x6003e5128)>>> DATA Net::SMTPS=GLOB(0x6003e5128)<<< 354 Go ahead b67sm22450316yhc.16 - gs +mtp Net::SMTPS=GLOB(0x6003e5128)>>> From: address@gmail.com Net::SMTPS=GLOB(0x6003e5128)>>> To: send_to@xxx.com Net::SMTPS=GLOB(0x6003e5128)>>> Reply-To: address@gmail.com Net::SMTPS=GLOB(0x6003e5128)>>> Subject: Hello! Net::SMTPS=GLOB(0x6003e5128)>>> Date: Sun, 20 Jul 2014 08:53:59 -0500 Net::SMTPS=GLOB(0x6003e5128)>>> MIME-Version: 1.0 Net::SMTPS=GLOB(0x6003e5128)>>> Content-Type: text/html; charset=UTF-8 Net::SMTPS=GLOB(0x6003e5128)>>> Just testing it<br>Bye! Net::SMTPS=GLOB(0x6003e5128)>>> . Net::SMTPS=GLOB(0x6003e5128)<<< 250 2.0.0 OK 1405864442 b67sm22450316y +hc.16 - gsmtp Net::SMTPS=GLOB(0x6003e5128)>>> QUIT Net::SMTPS=GLOB(0x6003e5128)<<< 221 2.0.0 closing connection b67sm2245 +0316yhc.16 - gsmtp
      What a great forum! Thanks to all for the help. Some of the suggestions will help later as I create useful code. Adding -layer=> 'ssl', and -port=> 465 resolved the problem.
Re: Problem using Gmail Send
by xyzzy (Pilgrim) on Jul 21, 2014 at 01:47 UTC

    This has nothing to do with Perl, but if at first you don't succeed, don't ever try to run it with super-user privileges. Most of the time the error is benign, but it makes the worst-case scenario an extremely-worst-case scenario.

    The same comment in image form


    $,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
    Happy, sober, smart: pick two.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1094329]
Approved by kevbot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2021-05-12 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (132 votes). Check out past polls.

    Notices?