Office365 Modern Authentication for IMAP, POP3, and SMTP

This post documents how to implement Modern Authentication (OAuth2) for Office365 for the IMAP, POP3, and SMTP protocols.  The very first thing you’ll need to do is to create an “App Registration” in Azure Active Directory.

See this Chilkat blog post for Instructions for Setting Up an App Registration in Azure for Modern Authentication for IMAP, SMTP, and POP3.

After registering your App in Azure Active Directory, you’ll need 4 pieces of information:

  1. Your Directory (tenant) ID
  2. Your Application (client) ID
  3. Your Application client secret value
  4. The localhost port number used in the Redirect URI, such as 3017.

 

Next, you’ll need to write code to get the initial OAuth2 access token.  Getting the initial OAuth2 access token will require your application to display a browser to interactively get authorization from the Office365 account owner (which may be yourself — yes, I know, it’s ridiculous if it’s your own Office365 account).

However, once you have the initial access token, it can be used and refreshed over and over without user interaction.  For example, if you need to interact with an Office365 mailbox through a non-interactive service or daemon, you can write a simple interactive utility program in the programming language of your choice to get the initial access token, and then use and auto-refresh from you service as needed.

Here are some links to examples for getting the initial OAuth2 access token: C# VB.NET Java Delphi VB6 VBScript Visual FoxPro Go Xojo

Important: For web-based applications, such as ASP or ASP.NET, you won’t use the Chilkat.OAuth2 class for getting the initial access token.  Instead, you’ll implement it directly in your ASP, ASP.NET or server-side code as demonstrated  at Implementing OAuth2 in ASP.NET  and Implementing OAuth2 in Classic ASP.

Also Note: Chilkat has spent much time and effort in trying to find out how to get an OAuth2 access token using the Client Credentials flow (i.e. a non-interactive OAuth2 flow) that can be used in the IMAP, POP3, and SMTP protocols.  So far, we have not been successful.  If it is at all possible, we don’t know the magical incantations that would make it succeed. At this point, we’re stuck with the need to interactively obtain the 1st OAuth2 access token.

Here are links to the Office365 category on example-code.com.  Each category web page contains links to examples for getting the initial access token, refreshing the access token, and then using the access token to authenticate with IMAP, POP3, and SMTP.

Office365 Examples for AutoIt
Office365 Examples for C
Office365 Examples for C#
Office365 Examples for C++
Office365 Examples for Chilkat2-Python
Office365 Examples for CkPython
Office365 Examples for Classic ASP
Office365 Examples for DataFlex
Office365 Examples for Delphi
Office365 Examples for Go
Office365 Examples for Java
Office365 Examples for Node.js
Office365 Examples for Objective-C
Office365 Examples for PHP Extension
Office365 Examples for Perl
Office365 Examples for PowerBuilder
Office365 Examples for PowerShell
Office365 Examples for PureBasic
Office365 Examples for Ruby
Office365 Examples for SQL Server
Office365 Examples for Swift
Office365 Examples for Tcl
Office365 Examples for VB.NET
Office365 Examples for VBScript
Office365 Examples for Visual Basic 6.0
Office365 Examples for Visual FoxPro
Office365 Examples for Xojo Plugin