1

Background: From May 30, 2022, ​​Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.

I have a Perl program that (via a cronjob) runs through all the mail sent to my Gmail account and does various things based on the contents of the email. This now crashes with an Authentication error.

I cannot see any way to overcome this running it as a cronjob. But is there some way to run it manually while logged in as the google user? I have tried doing that with no success.

Or is there a way to add the extra authentication required into the program? I am currently using the following rough code:

Net::IMAP::Simple;
IO::Socket::SSL;
Crypt::CBC;
Email::Simple;

$L = 'GoogleLogin';
$P = 'GooglePassword';

# Connect
$imap = Net::IMAP::Simple->new($Server, port  => 993,  use_ssl => 1,) || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";

# Log in
if ( !$imap->login( $L, $P ) ) {print  "Login failed for $L: " . $imap->errstr . "\n"; exit(64);}

# Look in the inbox
my $nm = $imap->select('Inbox');

## Iterate through all messages
for ($i = 1 ; $i <= $nm ; $i++ ) {
$message = $imap->get( $i ); #  or die "For $L Cannot get message number $i " . $imap->errstr . " \n";
@flags = $imap->msg_flags($i);

# Copy this message
$imap->create_mailbox( "Inbox.Processed" );
$imap->copy( $i, "Inbox.Processed" );  # or  die "For $L cannot move message number $i to Processed " . $imap->errstr . " \n";

# Copy to target.
$imap2->put( 'Inbox', $message, @flags ) or die "Problem with put of $L - " . $imap2->errstr . "\n";

$imap->delete( $i );
}

# Disconnect
$imap->quit;
Melchester
  • 421
  • 3
  • 18

0 Answers0