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

2024-03-31

我已经安装了this http://search.cpan.org/~mincus/Mail-Webmail-Gmail-1.09/lib/Mail/Webmail/Gmail.pm模块来获取 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 https://www.google.com/accounts/ServiceLoginBoxAuth)所以我觉得问题不在于找到URL。此外,我知道凭据是正确的并且可以在该 URL 上使用,因为我已经手动尝试过它们。

我在用着this http://search.cpan.org/~mincus/Mail-Webmail-Gmail-1.09/lib/Mail/Webmail/Gmail.pm#SAMPLE_TEST_SCRIPTS用于测试的脚本。我已在适当的地方提供了我的凭据。


I've also installed this http://search.cpan.org/~mishoo/Net-IMAP-Client-0.93/lib/Net/IMAP/Client.pm module with the same type of error.

Any idea why I'm getting blocked?

Use 如下所示。要通过 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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Perl 对 Gmail 进行身份验证? 的相关文章

随机推荐