By Admin on Friday, 10 May 2024
Category: All

sgcIndy XOAuth2 Delphi

​From sgcIndy 2024.5.0 the XOAuth2 Authentication mechanism is supported. The SASL XOAUTH2 mechanism for use with the IMAP AUTHENTICATE, POP AUTH, and SMTP AUTH commands. This mechanism allows the use of OAuth 2.0 Access Tokens to authenticate to a user's Gmail account for example.

​TIdSASLXOAuth2

The TIdSASLXOAuth2 has the event OnAuthenticate which is called before the Authorization is done. The event has 2 parameters:


If you want to send an email using the TIdSMTP component, just add the component TIdSASLXOAuth2 component as a new SASLMechanism.

​After configuring the SMTP and XOAuth2 components, send an email using the SMTP component and when the Authorization is required the event OnAuthenticate is called. Just set here the Username and the Access Token.

​OAuth2 Client

​The OAuth2 Access Token can be obtained using the TsgcHTTP_OAuth2_Client​ from the sgcWebSockets library.

Find below an example of how configure the OAuth2 client to obtain an OAuth2 Access Token from your google user account.

Delphi XOAuth2 Demo

Find below a demo that shows the XOAuth2 component with the OAuth2 Client from the sgcWebSockets library to send an email using the SMTP Protocol. Select the tab XOAuth2 to use this type of Authentication and fill the fields: 

  1. Username
  2. OAuth2 Client Id
  3. OAuth2 Client Secret
  4. Address to send the email

This browser does not support the video element.

Related Posts