Office 365 settings


after one day of trying, I have a solution now, that I want to document here:

I use Office 365 as an Email provider in my company. In this tutorial I explain how to set it up. I assume, that you are the owner & admin of the office 365 company account.

Email Server
goto: → Exchange
goto ‘Mail Flow’ → Connectors

Add a Connector
From: E-Mail Server of your company
To: Office 365
Add the IP of your ERP-next Server

While setting up you Domain, you will create a MX-record that looks something like:

Preparing the Email Account
Your Email Account can not be a admin in your organisation! If that is the case you have to deactivate the azure security defaults: Bereitstellen eines Standardsicherheitsniveaus in Azure Active Directory - Microsoft Entra | Microsoft Learn

Create a non-admin Email account.

Goto >> Users >> Multi-Factor-Authentication
Click on your user and deactivate MFA in the quicksteps.

ERPnext >> Settings >> Email Domain
Email Server:
Use IMAP: true
Use SSL: true
Port: 993

SMTP Server:
Use TLS: true
Use SSL: false
Port: 25

ERPnext >> Settings >> Email Account
Email Address:
Password: YourPassword


Disable SMTP server authentication: true

Let me know if that worked for you. I spend one day figuring out what to set up - hopfully this post helps you to do it quicker.

I am well aware, that you can use MFA and create an APP-Password. Feel free to contribute a tutorial if you need that.
You can set up App passwords here, after you have activated MFA.



Thanks for this guide. It works partially for me. All outgoing email is marked as Spam as it fails the SPF checks.

Now I need to configure the SPF domain settings to add the ERPNext hosted servers as permitted senders for my domain. I’ve asked ERPNext on a support ticket for these details.

I have created a for this. Can we set up? Need help @JanMrlth
Stuck after this process:
Add the IP of your ERP-next Server

how to add an email account if we are using Gmail as a mailing service.
Because, when I am creating an email account, it shows an error.

Server Error

Close Report

TypeError: Object of type ‘error’ is not JSON serializable

How to resolve this error?

what exactly is the problem?
Goto Sign in to your account
And follow these instructions: SMTP Relay

You might want to check, if your IP is blocked by Microsoft.

Login to the machine, that runs erpnext and is used to send the emails.

open a telnet connection:

telnet 25

HELO [your domain]

MAIL FROM: [sender email]

RCPT TO: [recipient email ]
550 5.7.511 Access denied, banned sender[YOUR IP ADDRESS]. To request removal from this list please forward this message to For more information please go to Email non-delivery reports and SMTP errors in Exchange Online | Microsoft Learn. AS(1410) []

Contact Microsoft Support, if you get a 550 here.


Hi Jan,

I tried everything you have described also I have read the SMTP Relay manual, but no luck.
I keep getting the following error when I try to send an email:

smtplib.SMTPSenderRefused: (530, b'5.7.57 Client not authenticated to send mail. [ZR0P278CA0015.CHEP278.PROD.OUTLOOK.COM]', 'Mert Somun ')

Mert Somun

As long as your company has the ‘security defaults’ enabled, this overrides all settings and does not allow you to use ‘legacy authentication’.

The only way to send mail, is via the SMTP relay. Have you created the connector? The IP is the only check, if you are allowed to send mail. There is no other AUTH for the SMTP relay.

Hi Jan,

Did I mis something? I also don’t have error log. Also when i do send email I dont get an error.

Domain settings:

Email Account Settings:

Connector added:

Azure security defaults:

Disabled SMTP AUTH:

Hi Jan,

Now it is working I don’t know if it has to do something with time or with my latest move; delist portal:

Mert Somun

1 Like

I never got a useful reply to my request for support on this and I had no time spare to devote to it.

The email servers used by ERPNext (for my hosted instance) are at
Their IP blocks are listed on their website:
I created a DNS TXT record for my domain like this:
v=spf1 ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip6:2001:bc8::/32 -all

This contains all the poneytelecom IP space (to mark ERPNext originating emails as permitted) and the Office 365 mail servers.

It’s covering a very large IP space, but I can’t narrow it down any further without help from ERPNext support.

Hi Jan
Please if you can clarify which password: regular or App password
I have tried with App password, attached config

It give me invalid outgoing mail server or port?

Where is the problem!

1 Like

I have tried this but no luck so far.

this is seriously frustrating … I get the following error:

Error connecting via SMTP: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)

I am using bench 5.15.2, and I generated the SSL certificates through the bench lets encrypt script.

does anybody have any idea what I might do?

Probably related to end of support of basic auth from Microsoft, just OAuth from now.

Work in progress on this PR:

I think it is near to merge.
Be patient. :slight_smile:

1 Like

Sigh. Thanks

Hi @JanMrlth,

I have followed your guide but I seem to get an error.

Invalid Outgoing Mail Server or Port: SMTP AUTH extension not supported by server.

What I’m I doing wrong?