blob: b1481478d684335c12e064c52483d134f93bf55f [file]
= Mail Microsoft Oauth Component
:doctitle: Mail Microsoft Oauth
:shortname: mail-microsoft-oauth
:artifactid: camel-mail-microsoft-oauth
:description: Camel Mail OAuth2 Authenticator for Microsoft Exchange Online
:since: 3.18.4
:supportlevel: Stable
//Manually maintained attributes
:camel-spring-boot-name: mail-microsoft-oauth
*Since Camel {since}*
The Mail Microsoft OAuth2 provides an implementation of `org.apache.camel.component.mail.MailAuthenticator` to authenticate IMAP/POP/SMTP connections and access to Email via Spring's Mail support and the underlying JavaMail system.
Maven users will need to add the following dependency to their `pom.xml`
for this component:
[source,xml]
------------------------------------------------------------
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mail-microsoft-oauth</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
------------------------------------------------------------
Importing `camel-mail-microsoft-oauth` it will automatically import camel-mail component.
== Microsoft Exchange Online OAuth2 Mail Authenticator IMAP sample
To use OAuth, an application must be registered with Azure Active Directory.
Follow the instructions listed in https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app[Register an application with the Microsoft identity platform] guide to register a new application. +
Enable application to access Exchange mailboxes via client credentials flow. Instructions https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth[here] +
Once everything is set up, declare and register in the registry, an instance of `+org.apache.camel.component.mail.MicrosoftExchangeOnlineOAuth2MailAuthenticator+`. +
For Example in a Spring Boot application:
[source,java]
---------------------------------------------------------------------------------
@BindToRegistry("auth")
public MicrosoftExchangeOnlineOAuth2MailAuthenticator exchangeAuthenticator(){
return new MicrosoftExchangeOnlineOAuth2MailAuthenticator(tenantId, clientId, clientSecret, "jon@doe.com");
}
---------------------------------------------------------------------------------
and then reference it in the Camel URI:
[source,java]
---------------------------------------------------------------------------------------
from("imaps://outlook.office365.com:993"
+ "?authenticator=#auth"
+ "&mail.imaps.auth.mechanisms=XOAUTH2"
+ "&debugMode=true"
+ "&delete=false")
---------------------------------------------------------------------------------------