如何使用 Perl 对 Gmail 进行身份验证?

发布于 2024-08-23 15:55:09 字数 1017 浏览 2 评论 0原文

我已经安装了这个 用于获取 Gmail 收件箱内的访问和控制的模块。然而,当我尝试通过一个小的 Perl 脚本进行连接并测试功能时,我收到此错误消息。

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

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

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

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


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

Any idea why I'm getting blocked?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我三岁 2024-08-30 15:55:09

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

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();
咿呀咿呀哟 2024-08-30 15:55:09

我正在使用 Mail::POP3Client 成功访问 Gmail 帐户(准确地说是 google apps 帐户)

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

所谓喜欢 2024-08-30 15:55:09

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

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

(此答案更适合 超级用户不过!)

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

楠木可依 2024-08-30 15:55:09

您可以尝试使用以下模块

  Mail::Webmail::Gmail

You can tried with the following module

  Mail::Webmail::Gmail
梦里泪两行 2024-08-30 15:55:09

您也可以使用以下代码

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  = '[email protected]';
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;

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  = '[email protected]';
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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文