3

我已安装模块以在 Gmail 收件箱中获得访问权和控制权。但是,当我尝试通过一个小的 Perl 脚本连接并测试功能时,我收到了这个错误消息。

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

这是在 Gmail.pm 模块中构建的错误。

我可以 ping 有问题的 URL(https://www.google.com/accounts/ServiceLoginBoxAuth),所以我觉得问题在于找不到 URL。此外,我知道凭据是正确的并且可以在该 URL 上工作,因为我已经手动尝试过它们。

我正在使用这个脚本进行测试。我已在适当的地方提供了我的凭据。


我也安装了这个模块,但出现了相同类型的错误。

知道为什么我会被阻止吗?

4

5 回答 5

12

使用Mail::IMAPClient如下所示。要通过 Mail::IMAPClient 通过 SSL 身份验证,您应该安装来自 Net::SSLeay 的 IO::Socket::SSL。如果是这样,这就像一个魅力。

#!/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();
于 2010-03-02T18:02:39.993 回答
2

我正在使用 Mail::POP3Client 成功访问 gmail 帐户(准确地说是 Google 应用程序帐户)

于 2010-03-02T16:12:00.650 回答
2

如果您也无法通过普通的 POP3 或 IMAP 访问 gmail,那么您的问题是配置问题而不是编程问题。

我使用此处描述的配置详细信息从 gmail(实际上是使用相同界面的 Google Apps)获取邮件:http: //download.gna.org/hpr/fetchmail/FAQ/gmail-pop-howto.html

(不过,这个答案更适合超级用户!)

于 2010-03-02T17:57:58.743 回答
0

您可以尝试使用以下模块

  Mail::Webmail::Gmail
于 2010-03-03T05:49:19.210 回答
0

您也可以使用以下代码

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;
于 2010-03-04T06:49:20.107 回答