Using OAuth2 to authenticate

Some servers (e.g Google Mail) provide support for OAuth2 authentication. With ImapX, you can authenticate using your login and a token:

var client = new ImapClient("imap.gmail.com", true);

if(client.Connect()) {
     
     var credentials = new OAuth2Credentials("login", "token");

     if(client.Login(credentials)) {
          // login successful
     }

}
else {
     // connection not successful
}