Outlook OAuth Fails to Send Email

Version: 25.04.2.6

I have a personal Outlook account (not MS365), and set up email alerts with Outlook OAuth per instructions from the 25.04 TrueNAS documentation. After going through the OAuth flow i get the expected “Outlook Credentials Have been Saved” message and it appears the the OAuth credentials are saved, as i don’t see any error messages in the middleware log after i re-do the OAuth flow. When i try to send a test email via the General Settings > Email window i get this:

 Error: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/middlewared/plugins/mail.py", line 370, in send_raw
    with self._get_smtp_server(config, message['timeout'], local_hostname=local_hostname) as server:
  File "/usr/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/plugins/mail.py", line 426, in _get_smtp_server
    self.middleware.call_sync('mail.outlook_xoauth2', server, config)
  File "/usr/lib/python3/dist-packages/middlewared/main.py", line 1041, in call_sync
    return methodobj(*prepared_call.args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/plugins/mail_/outlook.py", line 47, in outlook_xoauth2
    raise CallError("Outlook XOAUTH2 failed: %r %r" % (code, response))
middlewared.service_exception.CallError: [EFAULT] Outlook XOAUTH2 failed: 535 b'5.7.3 Authentication unsuccessful [DM6PR03CA0092.namprd03.prod.outlook.com 2026-09-06T20:25:48.958Z 08DF0B5C3B46EB44]'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/middlewared/job.py", line 515, in run
    await self.future
  File "/usr/lib/python3/dist-packages/middlewared/job.py", line 562, in __run_body
    rv = await self.middleware.run_in_thread(self.method, *args)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/main.py", line 627, in run_in_thread
    return await self.run_in_executor(io_thread_pool_executor, method, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/main.py", line 624, in run_in_executor
    return await loop.run_in_executor(pool, functools.partial(method, *args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/schema/processor.py", line 178, in nf
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/schema/processor.py", line 52, in nf
    res = f(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/plugins/mail.py", line 261, in send
    return self.send_raw(job, message, config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/schema/processor.py", line 178, in nf
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/middlewared/plugins/mail.py", line 395, in send_raw
    raise CallError(f'Failed to send email: {e}')
middlewared.service_exception.CallError: [EFAULT] Failed to send email: [EFAULT] Outlook XOAUTH2 failed: 535 b'5.7.3 Authentication unsuccessful [DM6PR03CA0092.namprd03.prod.outlook.com 2026-09-06T20:25:48.958Z 08DF0B5C3B46EB44]'
 

oauth save succeeding then 535 5.7.3 on the actual send usually means the token is there but smtp xoauth2 is getting rejected for that personal outlook mailbox.

things that burned me: account is hotmail/outlook consumer and microsoft flipped the smtp auth / security defaults, or the app registration / consent TrueNAS used doesnt include the smtp scope the send path wants. redo the oauth flow once after checking microsoft account security for “app access” / recent blocks, and confirm you can still send via outlook web with that same mailbox.

if it still 535s, paste the full CallError line (redact tokens) plus whether this is @outlook.com/@hotmail.com vs a custom domain on outlook. personal outlook oauth on 25.04 has been flaky for a few people lately so it might not be your config.

redo the oauth flow once after checking microsoft account security for “app access” / recent blocks,

Not sure what this is. On a consumer (personal) outlook account, the security settings are pretty limited. I can turn on/off passwordless login and multi-step auth, manage my login methods and see where i’ve logged in. I don’t see any alerts for failed logins. To confirm: this is a username@outlook.com email address.

if it still 535s, paste the full CallError line (redact tokens)

Below are the entries from the /var/log/middlewared.log. I cut at the timestamp starting from when i re-did the auth flow and attempted to send a test email. I don’t see any tokens here.

[2026/09/07 14:33:04] (WARNING) MailService.outlook_xoauth2():30 - Outlook XOAUTH2 failed: 535 b'5.7.3 Authentication unsuccessful [DS1PR03CA0002.namprd03.prod.outlook.com 2026-09-07T18:33:04.834Z 08DF0B5018B67EF1]'. Refreshing access token
[2026/09/07 14:33:04] (DEBUG) MailService.outlook_xoauth2():32 - Requesting Outlook access token
[2026/09/07 14:33:10] (DEBUG) MailService.send_mail_queue():455 - Sending message from queue failed @cee:{"TNLOG": {"exception": "Traceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/middlewared/plugins/mail.py\", line 442, in send_mail_queue\n    with self._get_smtp_server(config) as server:\n  File \"/usr/lib/python3.11/contextlib.py\", line 137, in __enter__\n    return next(self.gen)\n           ^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/middlewared/plugins/mail.py\", line 426, in _get_smtp_server\n    self.middleware.call_sync('mail.outlook_xoauth2', server, config)\n  File \"/usr/lib/python3/dist-packages/middlewared/main.py\", line 1041, in call_sync\n    return methodobj(*prepared_call.args)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/middlewared/plugins/mail_/outlook.py\", line 47, in outlook_xoauth2\n    raise CallError(\"Outlook XOAUTH2 failed: %r %r\" % (code, response))\nmiddlewared.service_exception.CallError: [EFAULT] Outlook XOAUTH2 failed: 535 b'5.7.3 Authentication unsuccessful [DS1PR03CA0002.namprd03.prod.outlook.com 2026-09-07T18:33:10.313Z 08DF0B5018B67EF1]'", "type": "PYTHON_EXCEPTION", "time": "2026-09-07 18:33:10.373970"}}
[2026/09/07 14:33:17] (DEBUG) MailService.outlook_xoauth2():32 - Requesting Outlook access token
[2026/09/07 14:33:23] (WARNING) MailService.send_raw():391 - Failed to send email @cee:{"TNLOG": {"exception": "Traceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/middlewared/plugins/mail.py\", line 370, in send_raw\n    with self._get_smtp_server(config, message['timeout'], local_hostname=local_hostname) as server:\n  File \"/usr/lib/python3.11/contextlib.py\", line 137, in __enter__\n    return next(self.gen)\n           ^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/middlewared/plugins/mail.py\", line 426, in _get_smtp_server\n    self.middleware.call_sync('mail.outlook_xoauth2', server, config)\n  File \"/usr/lib/python3/dist-packages/middlewared/main.py\", line 1041, in call_sync\n    return methodobj(*prepared_call.args)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/middlewared/plugins/mail_/outlook.py\", line 47, in outlook_xoauth2\n    raise CallError(\"Outlook XOAUTH2 failed: %r %r\" % (code, response))\nmiddlewared.service_exception.CallError: [EFAULT] Outlook XOAUTH2 failed: 535 b'5.7.3 Authentication unsuccessful [DM6PR02CA0113.namprd02.prod.outlook.com 2026-09-07T18:33:23.346Z 08DF0BE0AE5FC420]'", "type": "PYTHON_EXCEPTION", "time": "2026-09-07 18:33:23.415259"}}
[2026/09/07 14:33:23] (ERROR) middlewared.job.run():528 - Job <bound method accepts.<locals>.wrap.<locals>.nf of <middlewared.plugins.mail.MailService object at 0x7ff5321a35d0>> failed: CallError("Failed to send email: [EFAULT] Outlook XOAUTH2 failed: 535 b'5.7.3 Authentication unsuccessful [DM6PR02CA0113.namprd02.prod.outlook.com 2026-09-07T18:33:23.346Z 08DF0BE0AE5FC420]'")
[2026/09/07 14:33:25] (ERROR) middlewared.reader():137 - Error in ShellWorkerThread.reader @cee:{"TNLOG": {"exception": "Traceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/middlewared/apps/webshell_app.py\", line 135, in reader\n    ).result()\n      ^^^^^^^^\n  File \"/usr/lib/python3.11/concurrent/futures/_base.py\", line 449, in result\n    return self.__get_result()\n           ^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3.11/concurrent/futures/_base.py\", line 401, in __get_result\n    raise self._exception\n  File \"/usr/lib/python3/dist-packages/aiohttp/web_ws.py\", line 394, in send_bytes\n    await self._writer.send(data, binary=True, compress=compress)\n  File \"/usr/lib/python3/dist-packages/aiohttp/http_websocket.py\", line 748, in send\n    await self._send_frame(message, WSMsgType.BINARY, compress)\n  File \"/usr/lib/python3/dist-packages/aiohttp/http_websocket.py\", line 628, in _send_frame\n    raise ClientConnectionResetError(\"Cannot write to closing transport\")\naiohttp.client_exceptions.ClientConnectionResetError: Cannot write to closing transport", "type": "PYTHON_EXCEPTION", "time": "2026-09-07 18:33:25.431539"}}```

thanks for the log. yeah that is the consumer outlook path dying on smtp xoauth2 even after a clean save.

from what ive seen on personal @outlook.com boxes lately, microsoft is just flaky with smtp + xoauth2 from apps like this. the security page really does not show much for consumer accounts, so you were not missing a hidden toggle.

practical outs people use:

  • send alerts through a different smtp (gmail app password, a tiny relay, or an smtp provider) and keep outlook as the inbox you read
    • or watch for a truenas update that refreshes the outlook oauth scopes / client
      i would not keep burning oauth redos on the same @outlook.com mailbox if web mail sends fine and middleware keeps 535ing. the token save succeeding then smtp rejecting is the giveaway it is on microsofts side for that account type.