I am using SQL Server 2017, trying to configure Database Mail. If I use smtp.gmail.com Database Mail works fine. However a client is using smtp.office365.com and I cannot get it to work. The error I get is:
The mail could not be sent to the recipients because of the mail server failure."
I know the credentials/config info I am passing work because I have a C# app that can send emails using the same information. For the Database Mail configuration I am using:
Basic Authentication
PORT = 587
Use SSL = True
Server Name = smtp.office365.com
..and yes the "Username" I am using for authentication - does match the "E-mail address" entry.
Anyone have an idea of why smtp.office365.com doesn't work in Database Mail?
One other note - every once in a while it does work - I just cannot get it work most of the time.
Problem Diagnosis
Start by diagnosing DatabaseMail issues via SSMS with SQL Server > Management > Database Mail (right-click) > View Database Mail Log. Example error messages you're likely to see include:
This, unfortunately, is a very generic error message. It probably means that your local server, .NET Framework, or the DatabaseMail.exe process itself has not yet been configured to enable the TLS 1.2 protocol, so is failing to connect using TLS 1.0 or TLS 1.1 protocols.
This means that "This server requires a secure connection (SSL)" has not been ticked. This must be ticked to enable the STARTTLS command that establishes a secure communications channel over which SMTP Basic authentication gets sent.
This means that the Office365 mailbox being used in the Basic authentication details has not yet had the SMTP AUTH property enabled on it.
SQL Server's DatabaseMail vs. smtp.office365.com requirements
How to set up a multifunction device or application to send email using Microsoft 365 or Office 365 says:
Speak to your organization's Exchange administrator to have this setting enabled or, if you have sufficient access yourself, you can do this via PowerShell:
How to set up a multifunction device or application to send email using Microsoft 365 or Office 365 also says:
References: