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:
- Username: the username of the account which sends the email
- Token: the OAuth2 Token. This must be obtained using any third-party component like the TsgcHTTP_OAuth2_Client from the sgcWebSockets library.
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:
- Username
- OAuth2 Client Id
- OAuth2 Client Secret
- Address to send the email
This browser does not support the video element.