OAUTH2 O365 Mail Config for Modern Auth

Describe the problem/error/question

Hey all I’m trying to setup n8n system mail to O365. I’m attempting to use oauth2 and an app registration to configure this for Modern Auth but I cannot get it to function. I am able to use the OAUTH config in a workflow to send mail so I know my O365 config is working.

What is the error message (if any)?

When I attempt to set the flags below in the docker compose.yml file and I’ve also tried to insert them directly into the config.json file

I’ve also tried as many combinations as possible of ports/security flags/anything I can think of that might help like port 25, ssl false/true, different o365 connection points for smtp that I found in the online docs, and so on with no luck

I have tested the connection in the docker container with telnet and it works fine

When I attempt to invite a user, I keep getting these errors:

Could not invite 28F2B5B3AA780000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:354:

environment:
  - N8N_BASIC_AUTH_ACTIVE=true
  - N8N_BASIC_AUTH_USER=correct scrubbed value
  - N8N_BASIC_AUTH_PASSWORD=correct scrubbed value
  - N8N_HOST=correct scrubbed value
  - WEBHOOK_URL=https://correct scrubbed value/
  - N8N_PROTOCOL=https
  - N8N_PORT=5678
  - NODE_ENV=production

  # Trust reverse proxy
  - N8N_EXPRESS_TRUST_PROXY=true

  # Email config
  - N8N_EMAIL_MODE=smtp
  - N8N_SMTP_HOST=smtp.office365.com
  - N8N_SMTP_PORT=587
  - N8N_SMTP_SECURE=false
  - N8N_SMTP_USER=correct scrubbed value
  - N8N_SMTP_SENDER=correct scrubbed value

  # OAuth2 details
  - N8N_SMTP_OAUTH2_TYPE=custom
  - N8N_SMTP_OAUTH2_CLIENT_ID=correct scrubbed value
  - N8N_SMTP_OAUTH2_CLIENT_SECRET=correct scrubbed value
  - N8N_SMTP_OAUTH2_TOKEN_URL=https://login.microsoftonline.com/correct scrubbed value/oauth2/v2.0/token
  - N8N_SMTP_OAUTH2_REFRESH_TOKEN=<insert your full refresh token>
  - N8N_SMTP_OAUTH2_USER=correct scrubbed value

Please share your workflow

No workflow as this is system mail

Share the output returned by the last node

no last node as this is system mail

Information on your n8n setup

  • n8n version:
  • --version 1.108.2
  • Database (default: SQLite):
  • SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Own
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Docker
  • Operating system:
  • azure #36~22.04.1-Ubuntu SMP Tue Jul 1 03:54:01 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
  • PRETTY_NAME=“Ubuntu 22.04.5 LTS”
    NAME=“Ubuntu”
    VERSION_ID=“22.04”
    VERSION=“22.04.5 LTS (Jammy Jellyfish)”

Welcome to the community @AmIAI

This is a configuration that should resolve your issues

{
  "email": {
    "mode": "smtp",
    "smtp": {
      "host": "smtp.office365.com",
      "port": 587,
      "secure": false,
      "auth": {
        "type": "OAuth2",
        "clientId": "your-client-id",
        "clientSecret": "your-client-secret",
        "accessToken": "your-access-token",
        "refreshToken": "your-refresh-token",
        "accessUrl": "https://login.microsoftonline.com/your-tenant-id/oauth2/v2.0/token",
        "user": "[email protected]"
      }
    },
    "sender": "[email protected]"
  }
}

Docker compose variables

environment:
  # ... your existing variables ...
  
  # Email config
  - N8N_EMAIL_MODE=smtp
  - N8N_SMTP_HOST=smtp.office365.com
  - N8N_SMTP_PORT=587
  - N8N_SMTP_SECURE=false
  - [email protected]
  - [email protected]

  # OAuth2 details
  - N8N_SMTP_OAUTH2_CLIENT_ID=your-client-id
  - N8N_SMTP_OAUTH2_CLIENT_SECRET=your-client-secret
  - N8N_SMTP_OAUTH2_ACCESS_TOKEN=your-access-token
  - N8N_SMTP_OAUTH2_REFRESH_TOKEN=your-refresh-token
  - N8N_SMTP_OAUTH2_TOKEN_URL=https://login.microsoftonline.com/your-tenant-id/oauth2/v2.0/token
  - [email protected]

Thanks for the reply my friend! Unfortunately, I’ve tried these exact settings and received the same error.

Do you have this working in your environment?

Hey @AmIAI let me know when you are active let’s troubleshoot this together.

@Zelite Sorry for the delay as I was out on vacation last week. I’m around all this week if you are as well and happy to dive in for some troubleshooting, sir :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.