Microsoft SQL Server Database Mail (and SQL Agent alerts) with Microsoft 365: email through Microsoft 365 after Basic auth ends
Short answer: Database Mail has no OAuth option: its SMTP Authentication choices are Windows, Basic or Anonymous. A Basic authentication account on smtp.office365.com stops working when Basic auth is switched off. Point the account at your MX host on port 25 with Anonymous authentication behind a relay connector, or use a local relay.
Deadline: Microsoft 365 turns off SMTP AUTH Basic auth by default at the end of December 2026 – dates and background.
Modern authentication (OAuth) support
Not documented. Microsoft's Database Mail pages (SQL Server 2017 to 2025 and Azure SQL Managed Instance) list three SMTP Authentication options: Windows Authentication using Database Engine service credentials (NTLM, which Microsoft says is only available with Exchange on-premises), Basic Authentication (user name and password) and Anonymous authentication. sysmail_add_account_sp has no token or OAuth parameter either. So an account that logs in to smtp.office365.com with a mailbox password is Basic auth and is hit by the SMTP AUTH Basic auth switch-off. SQL Server 2016 is not covered by the current pages; OAuth for it is not documented either. The TDS 8.0 support added in SQL Server 2025 is about client connections to SQL Server, not about SMTP sign-in.
What you will see when it breaks
- "Failure to authenticate with the SMTP server." (Microsoft Learn: one of the failures logged in sysmail_event_log)
- Mail items stay in sysmail_unsentitems with status retrying, then move to sysmail_faileditems (Microsoft Learn: Database Mail retries each account, by default 5 attempts 60 seconds apart)
- Reported: The mail could not be sent to the recipients because of the mail server failure. ... Cannot send mails to mail server. (The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail. Error: 535 5.7.139 Authentication unsuccessful, basic authentication is disabled. (Microsoft Q&A, Dec 2024)
- "535 5.7.3 Authentication unsuccessful" or "5.7.57 Client not authenticated to send mail" (Microsoft Learn: SMTP AUTH login refused; check that Authenticated SMTP is on for the mailbox)
- SQL Agent job and alert notifications to operators stop arriving (they go through the same Database Mail profile)
Best fix
- Find the failing account. In SSMS go to Management → Database Mail → View Database Mail Log, or run
SELECT * FROM msdb.dbo.sysmail_event_log;and joinsysmail_faileditemsonmailitem_id. To list every mailbox in the tenant that still logs in over SMTP AUTH, run the free SMTP AUTH sender script. - Open the account: right-click Database Mail → Configure Database Mail → Manage Database Mail accounts and profiles → View, change, or delete an existing account. Server name
smtp.office365.comwith Basic Authentication is the setup that fails once Microsoft turns Basic auth off by default at the end of December 2026. - In Exchange admin center, create a relay connector (Mail flow → Connectors, from Your organization's email server) that trusts the static public IP your SQL Server sends from.
- Change the account: Server name your MX host (for example
contoso-com.mail.protection.outlook.com), Port number 25, SMTP Authentication Anonymous authentication. Scripting it? Insysmail_add_account_sp,@port = 25and@username = NULLmeans no authentication (Microsoft Learn). - Set E-mail address to an address in a domain your tenant owns, or Microsoft 365 rejects the message (see 550 5.7.64 TenantAttribution).
- Right-click Database Mail → Send Test E-Mail. If nothing happens, check
EXEC msdb.dbo.sysmail_help_status_sp;and start it withEXEC msdb.dbo.sysmail_start_sp;, then readsysmail_event_logagain. - Azure SQL Managed Instance: SQL Agent mail must use the profile
AzureManagedInstance_dbmail_profile, and the SMTP port needs an outbound rule in the instance's network security group (Microsoft Learn). The relay connector needs a static IP that you control; how that maps to Managed Instance outbound traffic is not documented.
If it can't do OAuth
- No static IP for a relay connector? Point Database Mail at a local SMTP relay on your network that signs in to Microsoft 365 itself. Microsoft's Managed Instance guide recommends an authenticated SMTP relay service and suggests one already in your on-premises servers.
- Without a connector, the MX host on port 25 is direct send, which only reaches mailboxes inside your organization (Microsoft Learn). Fine for a DBA team mailbox, not for outside recipients. See 550 5.7.68 if direct send is blocked in your tenant.
- Don't use Windows Authentication using Database Engine service credentials for Microsoft 365: Microsoft says it is only available with Exchange on-premises.
- Stopgap only: an admin can turn Basic auth for SMTP AUTH back on for now. It ends when Microsoft removes it for good; the date is due in the second half of 2027. See the SMTP AUTH change.
| Wizard path (SSMS) | Object Explorer > Management > Database Mail > Configure Database Mail |
|---|---|
| SMTP Authentication options | Windows Authentication using Database Engine service credentials, Basic Authentication, Anonymous authentication |
| OAuth / XOAUTH2 | Not documented (no OAuth option in the wizard or in sysmail_add_account_sp) |
| Relay connector values | Server name: your MX host, Port number: 25, SMTP Authentication: Anonymous authentication |
| T-SQL account parameters | @mailserver_name, @port (default 25), @username (NULL = no authentication), @password, @use_default_credentials, @enable_ssl |
| Logs and views | msdb.dbo.sysmail_event_log, sysmail_faileditems, sysmail_unsentitems, sysmail_sentitems, sysmail_allitems |
| Retry defaults | Account Retry Attempts 5, Account Retry Delay 60 seconds |
| Azure SQL Managed Instance | SQL Agent profile must be named AzureManagedInstance_dbmail_profile; outbound NSG rule for the SMTP port |
| Azure SQL Database | Database Mail not available |
Check your domain's SPF and DMARC
A relay sends from your office IP, so it must be in your SPF record.
Get the kit ($19)
Rather have it done for you? I move your devices and apps on Fiverr – relay, Direct Send or OAuth, tested, from $25.
Sources
- Microsoft Learn: Configure Database Mail (wizard fields, SMTP Authentication options)
- Microsoft Learn: Database Mail (architecture, availability)
- Microsoft Learn: sysmail_add_account_sp (Transact-SQL)
- Microsoft Learn: Troubleshoot Database Mail issues (sysmail views, Database Mail log)
- Microsoft Learn: General Database Mail troubleshooting
- Microsoft Learn: Job automation with SQL Agent jobs in Azure SQL Managed Instance (Database Mail)
- Microsoft Learn: Enable or disable SMTP AUTH in Exchange Online
- Microsoft Learn: How to set up a multifunction device or application to send email using Microsoft 365
- Microsoft Learn: Fix issues with printers, scanners, and LOB apps that send email using Microsoft 365
- Microsoft Exchange Team: Updated Exchange Online SMTP AUTH Basic Authentication deprecation timeline (MC786329)
- Microsoft Q&A (user report): Unable to send emails from SQL Server (535 5.7.139)
Other devices and apps
- HP printers and MFPs
- Canon imageRUNNER ADVANCE and i-SENSYS/imageCLASS
- Ricoh MFPs and printers
- Xerox AltaLink and VersaLink
- Brother printers, MFCs and scanners
- Konica Minolta bizhub
- Kyocera TASKalfa and ECOSYS
- Sharp MX and BP series
- Lexmark
- Epson WorkForce and EcoTank business
- Toshiba e-STUDIO (e-BRIDGE Next) scan to email with Microsoft 365
- FUJIFILM Apeos and ApeosPort (formerly Fuji Xerox) scan to email with Microsoft 365
- WordPress SMTP plugins (WP Mail SMTP, FluentSMTP, Post SMTP) with Microsoft 365
- Synology DSM and QNAP QTS / QuTS hero email notifications with Microsoft 365
- PowerShell Send-MailMessage with Microsoft 365
- Veeam Backup & Replication email notifications with Microsoft 365
- Zabbix email media type with Microsoft 365
- Paessler PRTG Network Monitor email notifications with Microsoft 365
- Windows Server IIS 6.0 SMTP relay forwarding app mail to Microsoft 365
- Sage 50 Accounts (UK and Ireland) and Sage 200 emailing invoices with Microsoft 365
- QuickBooks Desktop emailing invoices with Microsoft 365 (Web Mail or Outlook)
- Dell iDRAC and HPE iLO alert email (AlertMail) with Microsoft 365
- Jenkins email notifications (Mailer and Email Extension plugins) with Microsoft 365
- Microsoft 365 SMTP relay connector (any printer, scanner, NAS or app)