---
title: "Setup Microsoft Mail Account"
space: "ERPNext"
url: "https://docs.onfuse.ch/erpnext/setup-microsoft-mail-account"
updated: "2026-08-23"
---

From 2025 on, basic authentication is not enough to send emails from a Microsoft 365 Account. You have to setup OAuth from now on. In this guide we will lead you through the steps for setting it up.

# Step 1

First, you need to setup a Email Domain in ERPNext with the following settings.


|                           |                                                         |
| ------------------------- | ------------------------------------------------------- |
| Incoming Server           | outlook.office365.com                                   |
| Use IMAP                  | True                                                    |
| Use SSL                   | True                                                    |
| Validate SSL Certificate  | True                                                    |
| Port                      | 993                                                     |
| Attachment Limit          | 30 (Can be higher according to your Microsoft settings) |
| Outgoing server           | smtp.office365.com                                      |
| Use TLS                   | True                                                    |
| Use SSL                   | False                                                   |
| Validate. SSL Certificate | True                                                    |
| Port                      | 587                                                     |


# Step 2

Create a connected app called: Microsoft 365




|                      |                                                                                                                                                                                |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Name                 | Microsoft 365                                                                                                                                                                  |
| OpenID configuration | [https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration](https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration) |
|                      |                                                                                                                                                                                |


Afterwards press "Get OpenID Configuration"



Add the following scopes:

- [https://outlook.office.com/IMAP.AccessAsUser.All](https://outlook.office.com/IMAP.AccessAsUser.All)
- [https://outlook.office.com/SMTP.Send](https://outlook.office.com/SMTP.Send)
- [https://outlook.office.com/User.Read](https://outlook.office.com/User.Read)
- offline\_access



# Step 3

Create the endpoint in Microsoft: 

- In Microsoft Azure, create App Registration
- Create your own Application
- Name it ERPNext, leave the redirect URI empty
- Add these permissions for Microsoft Graph as delegated permissions: 
  - IMAP.AccessAsUser.All
  - offline\_access
  - SMTP.Send
  - User.Read
- Copy the application ID and fill that into ERPNext &gt; Client ID
- Certificates &amp; Secrets -&gt; New Client Secrets
- Fill the Secret into ERPNext &gt; Secret
- Add Authentication Redirect URI in Azure &gt; Web &gt; Paste the URI from ERPNext



# Step 4

- Open a private Window and sign into the Mail you wish to send the mails from
- Go to the connected app with your System Manager User and press "Connect to Microsoft 365" using your organizations admin account
- You should have a token now



# Step 5

- Change your method form your email account to oAuth and the domain to your previously created one.
- Login with the real Email Account





# Recommended settings

Email Account


|                                                 |       |
| ----------------------------------------------- | ----- |
| Enable Automatic Linking of Documents           | True  |
| Default Outgoing                                | True  |
| Send unsubscribe message in Email               | False |
| Always use this email address as sender address | True  |
| Always use this name as senders name            | True  |


# Common errors

- SMTP Authentication not successful
  - Check under the User &gt; Email &gt; Manage Email Apps &gt; Enable Authenticated SMTP