SQL Server 2016 Database Mail cannot send email smtp.office365.com

drcz 21 Reputation points
2020-12-03T06:34:02.883+00:00

SQL Server 2016 Database Mail and I get this error: Message The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2020-12-02T22:03:59). Exception Message: Cannot send mails to mail server. (Failure sending mail.). ) The configuration I use
Server: smtp.office365.com Port Number: 587 Authentication: Basic (An email address and password)

The server has disabled all SSL3 TLS 1.0 and 1.1, enabled TLS 1.2 Also .NET 4.7.1

Still not working...

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,750 questions
0 comments No comments
{count} votes

Accepted answer
  1. AmeliaGu-MSFT 13,961 Reputation points Microsoft Vendor
    2020-12-08T08:00:26.597+00:00

    Hi @drcz ,
    In addition, have you ticked “This server requires a secure connection(SSL)” in account tab?
    Please refer to this similar thread:

    Below is the content for a simple executable registry file that I put together that will make the 2 new settings and the settings already shown on the thread above (i.e. this makes all of the necessary Registry settings*):
    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v4.0.30319]
    "SchUseStrongCrypto"=dword:00000001

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft.NETFramework\v4.0.30319]
    "SchUseStrongCrypto"=dword:00000001

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2]

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
    "DisabledByDefault"=dword:00000000
    "Enabled"=dword:00000001

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
    "DisabledByDefault"=dword:00000000
    "Enabled"=dword:00000001
    Note 1: SQL needs to be restarted for these settings to take affect but it is better to restart Windows since the new settings will affect .NET 4.x generally.

    Note 2: In SQL, the SSL-checkbox must be ticked in the mail profile to use TLS1.2.

    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    4 people found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Olaf Helper 40,896 Reputation points
    2020-12-03T11:04:31.517+00:00
    0 comments No comments

  2. drcz 21 Reputation points
    2020-12-03T14:15:49.733+00:00

    I have seen the article just that I could not find the settings in a personal account. Is that working in the same way?

    0 comments No comments

  3. AmeliaGu-MSFT 13,961 Reputation points Microsoft Vendor
    2020-12-04T09:29:53.13+00:00

    Hi @drcz ,
    Could you please use Telnet to test SMTP communication?
    Please refer to Use Telnet to test SMTP communication and Testing SMTP with authentication from the command line which might help.
    In addition, quoting from this support article:

    Assume that you install Microsoft SQL Server 2016 on a computer that has the .NET Framework 4.6.1 installed. If the computer does not have the .NET Framework 3.5 installed, the Database Mail feature does not work correctly. For example, if you configure and send a test email message, the message is queued but is never sent.

    Please try to install SP1 and CU2 for SQL Server 2016.
    And to work around this issue, you can implement any one of the following:

    1. Create the DatabaseMail.exe.config and drop it next to the DatabaseMail.exe under the Binn folder. You can use notepad.exe or any other editor to edit it and save it by using UTF-8 encoding (in notepad.exe, select Save As... and in the Encoding combo box, select UTF-8):

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
    <supportedRuntime version="v2.0.50727"/>
    </startup>
    </configuration>

    1. Run a repair setup action of SQL Server 2016.
    2. Manually install .Net Framework 3.5 on the machine.
      Best Regards,
      Amelia

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    What can I do if my transaction log is full?--- Hot issues November
    How to convert Profiler trace into a SQL Server table -- Hot issues November

    0 comments No comments

  4. drcz 21 Reputation points
    2020-12-04T11:01:30.477+00:00

    Hi @AmeliaGu-MSFT
    is help me to do few more steps what did you send.

    My first step was to Use telnet to check.

    Send-MailMessage –From from@domain.com –To to@domain.com –Subject “Test Email” –Body “Test SMTP Relay Service” -SmtpServer smtp.office365.com -Credential $msolcred -UseSsl -Port 587  
    

    initially I had this error solved with [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

    Send-MailMessage : The client and server cannot communicate, because they do not possess a common algorithm
    At line:1 char:1

    • Send-MailMessage –From from@keyman .com –To to@keyman .com ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
      ion
    • FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

    meanwhile I have installed 3.5, uninstalled, then installed .net 4.8. and looks like SQL Serve it was updated to SP1 and CU. The same error when I try to send form Database Mail:

    Message
    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2020-12-04T12:29:26). Exception Message: Cannot send mails to mail server. (Failure sending mail.).
    )