How do I authenticate into Gmail using Perl?

萝らか妹 提交于 2019-12-09 19:10:17

问题


I've installed this module to gain access and controls within a Gmail inbox. However, when I try to connect through a small Perl script and test the functionality, I get this error message.

Error: Could not login with those credentials - could not find final URL
  Additionally, HTTP error: 200 OK

This is an error built within the Gmail.pm module.

I can ping the URL in question ( https://www.google.com/accounts/ServiceLoginBoxAuth ) so I feel that the trouble isn't finding the URL. Furthermore, I know the credentials are correct and work at that URL because I have tried them manually.

I'm using this script for testing. I have supplied my credentials in the appropriate places.


I've also installed this module with the same type of error.

Any idea why I'm getting blocked?

回答1:


Use Mail::IMAPClient as shown below. To get pass SSL authentication through Mail::IMAPClient, you should have IO::Socket::SSL from Net::SSLeay installed. If so this works like a charm.

#!/usr/bin/env perl
use strict; use warnings;
use Mail::IMAPClient;

# Connect to IMAP server
my $client = Mail::IMAPClient->new(
  Server   => 'imap.gmail.com',
  User     => 'yourusername',
  Password => 'yourp4a55w0r&',
  Port     => 993,
  Ssl      =>  1,
  )
  or die "Cannot connect through IMAPClient: $!";

# List folders on remote server (see if all is ok)
if ( $client->IsAuthenticated() ) {
  print "Folders:\n";
  print "- ", $_, "\n" for @{ $client->folders() };  
};

# Say so long
$client->logout();



回答2:


I am successfully accessing a gmail account (google apps account to be precise) using Mail::POP3Client




回答3:


If you cannot access gmail through normal POP3 or IMAP either, then you have a configuration problem rather than a programming problem.

I fetch my mail from gmail (actually Google Apps, which uses the same interface), using configuration details described here: http://download.gna.org/hpr/fetchmail/FAQ/gmail-pop-howto.html

(This answer is far more appropriate for Super User though!)




回答4:


You can tried with the following module

  Mail::Webmail::Gmail



回答5:


You can use the following code also

use warnings;
use strict;
use Mail::POP3Client;
use IO::Socket::SSL;
use CGI qw(:standard);
my $cgi = new CGI;
my $LOG ;
open $LOG , ">>filename" ;
my $username  = 'name@gmail.com';
my $password  = '*******' ;
 chomp($password);
my $mailhost  = 'pop.gmail.com';
my $port      = '995';

$cgi->header();

my $pop = new Mail::POP3Client(
USER     => $username,
PASSWORD => $password,
HOST     => $mailhost,
PORT     => $port,
USESSL   => 'true',
DEBUG     => 0,
);
if (($pop->Count()) < 1) {
exit;
}

print $pop->Count() . " messages found!:$!\n";

for(my $i = 1; $i <= $pop->Count(); $i++) {
 foreach($pop->Head($i)) {
 /^(From|Subject|Email):\s+/i && print $_, "\n";
 }

$pop->BodyToFile($LOG,$i);

}

$pop->Close();

exit;


来源:https://stackoverflow.com/questions/2364099/how-do-i-authenticate-into-gmail-using-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!