Recent

Author Topic: Work in progress: Secure SMTP With OAuth2 - Updated  (Read 995 times)

mjustin

  • Full Member
  • ***
  • Posts: 207
    • Habarisoft
Work in progress: Secure SMTP With OAuth2 - Updated
« on: August 03, 2025, 06:17:02 pm »
https://blog.habarisoft.com/2025/08/secure-delphi-smtp-with-oauth2/

Sending emails through Exchange Online using OAuth2 can be a robust, secure alternative to traditional username/password authentication. This post outlines how to achieve this in Object Pascal using the Indy components TIdHTTP and TIdSMTP, broken down into three practical steps.
  • Configure Exchange Online and Register an Entra ID App
  • Acquire an OAuth2 Access Token Using Indy TIdHTTP
  • Send Email Using Indy TIdSMTP with OAuth2 Access Token
Example FPCUnit project on GitHub.

Disclaimer: I have not yet been able to verify the Exchange Online configuration steps today, as I currently do not have access to an Exchange Online license.



Update - 2025-08-13
* An updated version with two fixes is now available on GitHub.
* Sending of emails using Indy TIdSMTP with the retrieved OAuth2 access token has been tested with success with the provided code.
« Last Edit: August 13, 2025, 07:16:51 pm by mjustin »

 

TinyPortal © 2005-2018