简体   繁体   中英

How do I authenticate into Gmail using Perl?

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?

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();

我使用Mail :: POP3Client成功访问了一个gmail帐户(准确地说是谷歌应用程序帐户)

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!)

您可以尝试使用以下模块

  Mail::Webmail::Gmail

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM