For non-Gmail clients, Gmail supports the standard IMAP and SMTP protocols. The Gmail IMAP and SMTP servers have been extended to support authorization via the industry-standard OAuth 2.0 protocol.
IMAP and SMTP use the standard Simple Authentication and Security Layer (SASL), via the native IMAP
AUTHENTICATE and SMTP
AUTH commands, to authenticate users. The SASL XOAUTH2 mechanism enables clients to provide OAuth 2.0 credentials for authentication. The SASL XOAUTH2 protocol documentation describes the SASL XOAUTH2 mechanism in great detail, and libraries and samples which have implemented the protocol are available.
Incoming connections to the IMAP server at
imap.gmail.com:993 require SSL. The outgoing SMTP server,
smtp.gmail.com, requires TLS. Use port
465, or port
587 if your client begins with plain text before issuing the STARTTLS command.
Libraries and Samples
Accessing mail using IMAP and sending mail using SMTP is often done using existing IMAP and SMTP libraries for convenience. As long as these libraries support the Simple Authentication and Security Layer (SASL), they should be compatible with the SASL XOAUTH2 mechanism supported by Gmail.
The Libraries and Samples page provides code samples in a variety of popular languages using the SASL XOAUTH2 mechanism with either IMAP or SMTP.