Skip to content

Instantly share code, notes, and snippets.

@kizashi1122
Created August 19, 2019 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kizashi1122/97b8ec2d80b47f51e53ba8c5889b092b to your computer and use it in GitHub Desktop.
Save kizashi1122/97b8ec2d80b47f51e53ba8c5889b092b to your computer and use it in GitHub Desktop.
pop3 xoauth2 authentication with Net::POP3
#!/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