Google recently started to enforce OAuth 2.0 authentication for IMAP, and give "Authentication failure" if not correctly provided.
Information about IMAP headers can be found here:
How to implement this with Rebex Secure Mail?
What I tried was to change my original code from:
But I get the ImapException
"Unexpected continuation request received from the server."