1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Mail::IMAPClient;
use MIME::Base64;
use Net::OAuth2::Profile::Password;
my $username = 'bal@gmail.com';
my $password = 'aabbccddeeffgghh';
my $auth = Net::OAuth2::Profile::Password->new(
client_id => $username,
client_secret => $password,
# grant_type => 'XOAUTH2',
);
my $oauth_sign = encode_base64("user=". $username ."\x01auth=Bearer ". $auth ."\x01\x01", '');
print "\n\n-->$oauth_sign<--\n";
my $imap = Mail::IMAPClient->new(
Server => 'imap.gmail.com',
User => $username,
Password => $password,
Timeout => 15,
Port => 993,
Ssl => 1,
Debug => 0,
) or die ("Erreur connexion $! - $@\n");
# BAD $imap->authenticate('XOAUTH2', sub { return $oauth_sign }) or die("Auth error: ". $imap->LastError);
$imap->Authenticated('XOAUTH2', $username, $oauth_sign ) or die("Auth error: ". $imap->LastError);
print $imap->folders or die("List folders error: ". $imap->LastError); |
Partager