Skip to content

Latest commit

 

History

History
64 lines (50 loc) · 3.67 KB

File metadata and controls

64 lines (50 loc) · 3.67 KB

Camel Spring Boot Microsoft Exchange IMAP Oauth2 Authentication

This is an example that shows how to use Camel on Spring Boot to connect with IMAP protocol and access email data for Office 365 users using OAuth2 authentication.

The application will use the client credentials grant flow to get the access token and use it to authenticate IMAP connections.

Prerequisite

  • To use OAuth, an application must be registered with Azure Active Directory. Follow the instructions listed in Register an application with the Microsoft identity platform to register a new application.

  • Enable application to access Exchange mailboxes via client credentials flow adding IMAP.AccessAsApp permission. Instructions here

  • Create and register your Azure Active Directory application’s service principal in Exchange via Exchange Online PowerShell. Instructions here

  • Edit the application.properties adding the values to the properties marked with <FILL-ME> tag

How to run

You can run this example using:

mvn spring-boot:run

And you should see this output:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.5)

2022-10-24 19:19:58.705  INFO 2274709 --- [           main] o.a.c.e.mail.oauth2.CamelApplication     : Starting CamelApplication
2022-10-24 19:19:58.707  INFO 2274709 --- [           main] o.a.c.e.mail.oauth2.CamelApplication     : No active profile set, falling back to 1 default profile: "default"
2022-10-24 19:20:00.777  INFO 2274709 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel is starting
2022-10-24 19:20:00.785  INFO 2274709 --- [           main] c.s.b.CamelSpringBootApplicationListener : Starting CamelMainRunController to ensure the main thread keeps running
2022-10-24 19:20:00.785  INFO 2274709 --- [inRunController] org.apache.camel.main.MainSupport        : Apache Camel (Main)  is starting
2022-10-24 19:20:00.813  INFO 2274709 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Routes startup (started:1)
2022-10-24 19:20:00.813  INFO 2274709 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Started camel-mail-ms-exchange (imaps://outlook.office365.com:993)
2022-10-24 19:20:00.813  INFO 2274709 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel (CamelMailExchangeOAuth2) started in 1s226ms (build:29ms init:1s163ms start:34ms)
2022-10-24 19:20:00.819  INFO 2274709 --- [           main] o.a.c.e.mail.oauth2.CamelApplication     : Started CamelApplication in 2.407 seconds (JVM running for 2.883)
2022-10-24 19:20:04.842  INFO 2274709 --- [fice365.com:993] camel-mail-ms-exchange                   : message Received:
From: John Doe <[email protected]>
Subj: Test
Body:
This is a Test!!!

2022-10-24 19:20:05.167  INFO 2274709 --- [fice365.com:993] camel-mail-ms-exchange                   : message Received:
From: Teigan Moore <[email protected]>
Subj: Prova
Body:
Prova Prova Prova
--
Teigan Moore