Jump to content
Registration disabled at the moment Read more... ×
Sign in to follow this  
mjustin

Send emails through Exchange Online using SMTP with OAuth2

Recommended Posts

Sending emails through Exchange Online using SMTP with OAuth2 can be a robust, secure alternative to traditional username/password authentication.

 

This project on GitHub is still "work in progress", but has successfully been tested now: https://github.com/michaelJustin/delphi-smtp-with-oauth2

 

The blog post https://blog.habarisoft.com/2025/08/secure-delphi-smtp-with-oauth2/ describes the three steps to send SMTP mails via Exchange Online with OAuth2 authorization and Object Pascal.

Step 1: Configure Exchange Online and Register an Entra ID App

Step 2: Acquire an OAuth2 Access Token Using Indy TIdHTTP and the Client Credentials Grant Flow 

Step 3: Send Email Using Indy TIdSMTP with OAuth2 Access Token

 

With under 150 lines of code, the project stays lean and transparent—making it easy to adopt, extend, prototype, and test without overhead.

 

Technical references: 

* Authenticate an IMAP, POP or SMTP connection using OAuth

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×