Created
August 19, 2019 06:29
-
-
Save kizashi1122/97b8ec2d80b47f51e53ba8c5889b092b to your computer and use it in GitHub Desktop.
pop3 xoauth2 authentication with Net::POP3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.28; | |
use utf8; | |
use Net::POP3; | |
use MIME::Base64; | |
my $user = 'myaccount@example.com'; | |
my $token = 'ya29.GltdBxoUGp4......'; # retrieve with OAuth2 | |
my $xoauth2_token = encode_base64("user=$user\001auth=Bearer $token\001\001"); | |
$xoauth2_token =~ s/[\r\n]//g; | |
my $pop = Net::POP3->new('pop.gmail.com', Port => 995, Timeout => 30, SSL => 1, Debug => 1); | |
my $res = $pop->command("AUTH XOAUTH2 $xoauth2_token")->response(); | |
# whatever you want here | |
$pop->quit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment