ERPNext Email Setup Fails on Save – SSL Error on Port 587 (Microsoft 365 + OAuth2)

Hi everyone,

I’m trying to set up outgoing email in ERPNext using Microsoft 365 SMTP with OAuth 2.0 authentication, but I’m encountering an error the moment I try to save the configuration.

Setup Details:
• ERPNext version: v16.x
• Mail provider: Microsoft 365 (Outlook / Exchange Online)
• SMTP Server: smtp.office365.com
• Port: 587
• Encryption Settings:
• SSL = :white_check_mark:
• TLS = :x:
• OAuth 2.0: Enabled (with a valid Azure AD app, permissions, and redirect URI)

Problem:

When I click Save on the Email Account form, I immediately get this error:

Invalid Outgoing Mail Server or Port: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1016)

This is preventing me from completing the email account setup — I can’t save the form at all.

Has anyone else run into this issue? Would appreciate any guidance or ideas.
Thanks!
Phil

For 465:

  • SSL :white_check_mark:
  • TLS :x:

For 587:

  • SSL :x:
  • TLS :white_check_mark: