[ 
https://issues.apache.org/jira/browse/EMAIL-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17953619#comment-17953619
 ] 

Manuel K edited comment on EMAIL-163 at 5/23/25 8:04 AM:
---------------------------------------------------------

Hey [~sgoeschl], [~ggregory],

I now came around to testing with your feature branch and it worked flawlessly. 
Here are some details, maybe also of use for future readers of this Jira issue:
 * Create an app registration in Entra ID with the permission "Office 365 
Exchange Online - SMTP.SendAsApp"
 * 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]

 * Get an Exchange Online access token (for example using the Graph API with 
the scope {_}[https://outlook.office365.com/.default]{_})
 * SMTP server: smtp.office365.com, Port 587, StartTLS
 * Username: The email address of the mailbox you want to send as
 * Password: The access token

{code:java}
email.setOAuth2Required(true);
email.setAuthentication(emailAddress, accessToken);{code}
[~sgoeschl]: It would be great if you could get the process started to get your 
code integrated?

[~ggregory]: Would it be possible to get a 2.0.0-M2 or 2.0.0 afterwards, so 
people can comfortably use this feature?

Thank you very much in advance!

 


was (Author: JIRAUSER299045):
Hey [~sgoeschl], [~ggregory],

I now came around to testing with your feature branch and it worked flawlessly. 
Here are some details, maybe also of use for future readers of this Jira issue:
 * Create an app registration in Entra ID with the permission "Office 365 
Exchange Online - SMTP.SendAsApp"
 * 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]

 * Get an Exchange Online access token (for example using the Graph API with 
the scope {_}https://outlook.office365.com/.default{_})
 * SMTP server: smtp.office365.com, Port 587, StartTLS
 * Username: The email address of the mailbox you want to send as
 * Password: The access token

 
{code:java}
email.setOAuth2Required(true);
email.setAuthentication(emailAddress, accessToken);{code}
[~sgoeschl]: It would be great if you could get the process started to get your 
code integrated?

[~ggregory]: Would it be possible to get a 2.0.0-M2 or 2.0.0 afterwards, so 
people can comfortably use this feature?

Thank you very much in advance!

 

> Support for OAuth2 authentication
> ---------------------------------
>
>                 Key: EMAIL-163
>                 URL: https://issues.apache.org/jira/browse/EMAIL-163
>             Project: Commons Email
>          Issue Type: New Feature
>    Affects Versions: 1.4
>            Reporter: Guillaume Grossetie
>            Assignee: Siegfried Goeschl
>            Priority: Major
>              Labels: OAuth2
>
> {quote}
> Starting with JavaMail 1.5.5, support for OAuth2 authentication is built-in 
> and no longer requires SASL (although the SASL OAuth2 support continues to 
> work).
> {quote}
> https://java.net/projects/javamail/pages/OAuth2
> It would be great if commons email could provide an API to support OAuth2 
> authentification.
> The following code should be integrated in {{Email.getMailSession}}:
> {code}
> if (isOAuth2Authentication()) {
>   props.put("mail.smtp.auth.mechanisms", "XOAUTH2");
> }
> {code}
> Or a generic solution:
> {code}
> if (this.authMechanisms != null) {
>   props.put("mail.smtp.auth.mechanisms", this.authMechanisms);
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to