Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Gmail ssl pop mail stopped working. (SOLVED)

by zentara (Archbishop)
on Jul 22, 2011 at 18:10 UTC ( [id://916182]=perlquestion: print w/replies, xml ) Need Help??

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

July 23, 2011 I took a look at Email::Send::SMTP::Gmail and although it didn't say it in the description, it uses the ssl connection on port 465, AND IT WORKS!. After looking closely at the module's code, I guess my code must be missing a Content-Type header, or some little detail. So you can use Email::Send::SMTP::Gmail for ssl. See example module code below in response.

Hi, a recent node here on Gmail got me to test my Gmail ssl script, which worked last year, which was the last time I tried it. Now, the script executes without error, but the mail dosn't show up in Gmail. The instructions are on gmail configure page. Here is the script. It works past the auth, because it dosn't die there, and it prints done, so I know I'm connecting. However, no message appears in my Gmail inbox.

P.S. ssl sending and receiving works fine from my regular gui mail program using these settings.

#!/usr/bin/perl use warnings; use strict; use Net::SMTP::SSL; + my $user = 'me@gmail.com'; my $pass = 'foobarbaz'; #$server = 'your-smtp-server'; my $server = 'smtp.gmail.com'; my $to = 'me@gmail.com'; my $from_name = 'me'; my $from_email = 'me@gmail.com'; my $subject = 'smtp-ssl-auth test'; my $smtps = Net::SMTP::SSL->new($server, Port => 465, DEBUG => 1, ) or warn "$!\n"; # I just lucked out and this worked defined ($smtps->auth($user, $pass)) or die "Can't authenticate: $!\n"; $smtps->mail($from_email); $smtps->to($to); $smtps->data(); $smtps->datasend("To: $to\n"); $smtps->datasend(qq^From: "$from_name" <$from_email>\n^); $smtps->datasend("Subject: $subject\n\n"); $smtps->datasend("This will be the body of the message.\n"); $smtps->datasend("\n--\nVery Official Looking .sig here\n"); $smtps->dataend(); $smtps->quit(); print "done\n";

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re: Gmail ssl pop mail stopped working. (SOLVED)
by zentara (Archbishop) on Jul 23, 2011 at 14:09 UTC
    Working code:

    #!/usr/bin/perl use warnings; use strict; use Email::Send::SMTP::Gmail; # uses ssl connection on port 465, even though the module name # nor the module's perldoc mentions ssl. You have to read the module # source to see it my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'gmail.com', -login=>'me@gmail.com', -pass=>'foobarbaz'); $mail->send(-to=>'me@gmail.com', -subject=>'Hello ssl smtp test', -verbose=>'1', -body=>'Just testing it', # -attachments=>'full_path_to_file', ); $mail->bye;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Gmail ssl pop mail stopped working. (SOLVED)
by zentara (Archbishop) on Jul 23, 2011 at 15:13 UTC
    Well just because I'm an obsessive programmer, who can't stand it when a module's code works, and mine don't, I finally got my manual version to work by closely examining the module's methods. :-) Use the module, it's way better. This just demonstrates how to waste half an hour of eye strain. :-)
    #!/usr/bin/perl use warnings; use strict; use Net::SMTP::SSL; + my $user = 'me@gmail.com'; my $pass = 'foobarbaz'; my $server = 'smtp.gmail.com'; my $to = 'me@gmail.com'; my $from_email = 'me@gmail.com'; my $subject = 'smtp-ssl-auth test'; my $smtps = Net::SMTP::SSL->new($server, Port => 465, DEBUG => 1, ) or warn "$!\n"; # authenticate defined ($smtps->auth($user, $pass)) or die "Can't authenticate: $!\n"; # send preliminary data $smtps->mail("$from_email\n"); $smtps->to("$to\n"); $smtps->data(); #send header $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"); #send text body $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(); print "done\n";

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://916182]
Approved by ww
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found