Devot Logo
Devot Logo
Arrow leftBack to blogs

Guide to Microsoft Outlook Mail Integration Using Microsoft Graph API

Tomislav B.5 min readJul 29, 2025Technology
Tomislav B.5 min read
Contents:
Why integrate Microsoft Outlook Mail?
How to register your app in the Microsoft Entra admin center for Outlook Mail integration
Set up your Java project in 7 steps
Conclusion

In today’s digital world, email integration is a critical feature for many applications—whether you’re building a productivity app, a customer support tool, or a collaboration platform.

Integrating Microsoft Outlook Mail via the Microsoft Graph API provides seamless email management, improved communication, and enhanced productivity by enabling features like sending emails, reading inbox messages, and managing folders directly within your app.

Why integrate Microsoft Outlook Mail?

Integrating Microsoft Outlook Mail into your app offers several benefits:

  • Seamless email management: Users can access and manage their emails directly within your app.

  • Improved communication: Send and receive emails programmatically.

  • Cross-platform compatibility: Outlook Mail is compatible with various devices and platforms.

  • Enhanced productivity: Automate email workflows and improve collaboration.

How to register your app in the Microsoft Entra admin center for Outlook Mail integration

Before diving into the code, the first step in integrating Microsoft Outlook Mail into your application is to register your app in the Microsoft Entra Admin Center.

This process ensures that your app is authorized to interact with the Microsoft Graph API and access Outlook Mail features. In this section, we’ll guide you through the registration process and explain how to set up your Java project for seamless integration.

To enable your app to authenticate users and access Outlook Mail, you need to register it in the Microsoft Entra Admin Center:

Register a new application

  • In the left-hand menu, select App registrations.

  • Click on New registration to create a new app.

  • Enter a name for your application.

  • Click Register to complete the registration.

 Screenshot of Microsoft Entra Admin Center showing the

Configure authentication settings

  • In the app’s overview page, select Authentication under the Manage section.

  • Scroll down to the Advanced settings section.

  • Toggle the Allow public client flows option to Yes.

  • Click Save to apply the changes.

Authentication settings page in Microsoft Entra Admin Center with the

Note down the client ID and tenant ID

  • From the app’s overview page, copy the Client ID and Tenant ID.

  • These values will be used in your Java application to authenticate with the Microsoft Graph API.

Microsoft Entra application overview page displaying the Client ID and Tenant ID used for Microsoft Graph API integration

Set up your Java project in 7 steps

1. Create a Java application

If you haven’t already, create a new Java project using your preferred IDE or build tool (e.g., Maven or Gradle).

2. Add required dependencies

To interact with Microsoft Graph API, you’ll need to add the following dependencies to your build.gradle file:

Add the following configuration to your application.properties file:

3. Add user authentication

To authenticate users and access Outlook Mail, you’ll use the Device Code Flow, which is ideal for non-interactive or command-line applications.

4. Configure the Graph client

  • The DeviceCodeCredential class handles the authentication process, while the GraphServiceClient is used to interact with the Microsoft Graph API.

5. Create a controller

  • Create a controller to handle authentication and expose an endpoint for connecting to Outlook.

6. Authenticate and connect to Outlook

When you run your application and call the /connect endpoint, the following will happen:

  • A device code and a URL will be displayed in the console.

  • Open the URL in a browser and enter the device code to authenticate.

  • Once authenticated, your app will be able to access Outlook Mail features.

7. Fetch Outlook email

Insert the following code into OutlookService

The function uses the request builder, which builds a request to the calendar API. This code will fetch an input number of emails for certain mail folders depending on what folder name we insert under the folderName variable. Table of possible folderName is:

Well-known folder name

Description

archive

The archive folder messages are sent to when using the One_Click Archive feature in Outlook clients that support it. Note: this isn't the same as the Archive Mailbox feature of Exchange Online.

clutter

The clutter folder low-priority messages are moved to when using the Clutter feature.

conflicts

The folder that contains conflicting items in the mailbox.

conversationhistory

The folder where Skype saves IM conversations (if Skype is configured to do so).

deleteditems

The folder items are moved to when they're deleted.

drafts

The folder that contains unsent messages.

inbox

The inbox folder.

junkemail

The junk email folder.

localfailures

The folder contains items that exist on the local client but couldn't be uploaded to the server.

msgfolderroot

The "Top of Information Store" folder. This folder is the parent folder for folders that are displayed in normal mail clients, such as the inbox.

outbox

The outbox folder.

recoverableitemsdeletions

The folder that contains soft-deleted items is deleted either from the Deleted Items folder or by pressing shift+delete in Outlook. This folder isn't visible in any Outlook email client, but end users can interact with it through the Recover Deleted Items from Server feature in Outlook or Outlook on the web.

scheduled

The folder contains messages that are scheduled to reappear in the inbox using the Schedule feature in Outlook for iOS.

searchfolders

The parent folder for all search folders is defined in the user's mailbox.

sentitems

The sent items folder.

serverfailures

The folder contains items that exist on the server but couldn't be synchronized to the local client.

syncissues

The folder contains synchronization logs created by Outlook.

  • Add a getEmailFolderMessages()method to your OutlookController.

This method will return a response with all emails from the targeted mail folder with all information. For more customization and to extract and manipulate desired data, check the Message class from com.microsoft.graph.models.

8. Sent Outlook mail

Email communication is a crucial feature in modern applications. We'll create a Spring Boot REST API that allows us to send emails programmatically.

  • Create the email service

We'll implement in the OutlookService the sendEmail method, which uses the Microsoft Graph API.

  • Build the controller

We'll expose an API endpoint that accepts email details in a JSON request body and triggers the email sending process using the provided sendEmail method.

  • Handling API requests

Using a simple DTO EmailRequest, we ensure structured and readable email input. This approach makes it easy to integrate email-sending functionality into any Spring Boot application.

Conclusion

Integrating Microsoft Outlook Mail into your app can provide powerful email management features to your users. By leveraging the Microsoft Graph API, you can easily fetch emails, send messages, and manage folders programmatically.

With the step-by-step guide provided in this blog, you can integrate Outlook Mail into your Java and Spring Boot applications and enhance its functionality. For more advanced use cases, explore the Microsoft Graph API documentation.

Spread the word:
Keep readingSimilar blogs for further insights
GitHub vs GitLab: Choosing the Right Platform for Your Development Workflow
Technology
Marko M.4 min readJul 23, 2025
GitHub vs GitLab: Choosing the Right Platform for Your Development WorkflowHead-to-head showdown between GitHub’s vast ecosystem and GitLab’s all-in-one DevOps powerhouse, revealing differences in repo management, CI/CD pipelines, security features, pricing, project-size suitability, and cutting-edge AI tools.
How to Integrate Microsoft Outlook Calendar into Your Spring Boot Application
Technology
Tomislav B.3 min readJul 17, 2025
How to Integrate Microsoft Outlook Calendar into Your Spring Boot ApplicationA step-by-step tutorial showing you how to: register a Spring Boot app in the Microsoft Entra admin center; add Graph SDK dependencies; set up DeviceCodeCredential for user authentication; fetch calendar events using start/end filters; and programmatically create new Outlook Calendar events via Microsoft Graph API.
How We Have Solved The Issue Of Searching Within Nested Nodes - API Platform
Technology
Karlo A.5 min readJul 9, 2025
How We Have Solved The Issue Of Searching Within Nested Nodes - API PlatformLearn how to set up an API Platform endpoint in Symfony that takes an organization or group ID (or UUID) and returns all related library units using either a Nested Data Set model or a recursive Doctrine extension.