This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a commit to branch Features/EMAIL-163
in repository https://gitbox.apache.org/repos/asf/commons-email.git


The following commit(s) were added to refs/heads/Features/EMAIL-163 by this 
push:
     new f1d76f20 EMAIL-163 Support for OAuth2 authentication
f1d76f20 is described below

commit f1d76f20678aefecef9e64d02e7f95735a9d681c
Author: sgoeschl <siegfried.goes...@gmail.com>
AuthorDate: Tue May 27 20:50:01 2025 +0200

    EMAIL-163 Support for OAuth2 authentication
---
 src/changes/changes.xml     |  1 +
 src/site/xdoc/userguide.xml | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 61ade7fd..12bc06f2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,7 @@
   <body>
     <release version="2.0.0-M2" date="YYY-MM-DD" description="Feature release 
(Java 8 or above).">
       <!-- ADD -->
+      <action type="add" due-to="Siegfried Goeschl" dev="sgoeschl" 
issue="EMAIL-163">Support for OAuth2 authentication.</action>
       <!-- FIX -->
       <!-- UPDATE -->
       <action type="update" due-to="Gary Gregory, Dependabot" 
dev="ggregory">Bump commons-parent from 72 to 78 #279, #293, #297, 
#304.</action>
diff --git a/src/site/xdoc/userguide.xml b/src/site/xdoc/userguide.xml
index 856a9b04..a0a568e8 100644
--- a/src/site/xdoc/userguide.xml
+++ b/src/site/xdoc/userguide.xml
@@ -337,6 +337,23 @@ import org.apache.commons.mail2.javax.*;
         to a known good address.
       </p>
     </section>
+    <section name="Using OAuth2 Authentication With Office 365">
+      <p>
+        Checklist provided by mkomko to help future users of this feature
+        <ul>
+          <li>Create an app registration in Entra ID with the permission 
"Office 365 Exchange Online - SMTP.SendAsApp"</li>
+          <li>Create a service principal in Exchange Online for the app and 
give it permissions to the mailbox you want to send as, as described in 
https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#use-client-credentials-grant-flow-to-authenticate-smtp-imap-and-pop-connections</li>
+          <li>Get an Exchange Online access token (for example using the Graph 
API with the scope https://outlook.office365.com/.default)</li>
+          <li>SMTP server: smtp.office365.com, Port 587, StartTLS</li>
+          <li>Username: The email address of the mailbox you want to send 
as</li>
+          <li>Password: The access token</li>
+        </ul>
+      </p>
+      <source><![CDATA[
+email.setOAuth2Required(true);
+email.setAuthentication(emailAddress, accessToken);
+]]></source>
+    </section>
   </body>
 </document>
 

Reply via email to