Unable to Send Emails from SQL Server

Avinash 20 Reputation points
2024-12-23T08:38:01.5766667+00:00

There is an issue with sending emails from SQL Server, accompanied by the following error message:

The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2024-12-03T11:05:46). Exception Message: 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. [DX0P273CA0027.AREP273.PROD.OUTLOOK.COM 2024-12-03T05:35:46.473Z 08DD12CC82639E81]).

This functionality was working fine for the last couple of years, but the error has started occurring in the last couple of weeks. Assistance is requested regarding this issue.

Additionally, no Exchange Admin Center is being used; a new mail account was created through Outlook login.

SQL Server on Azure Virtual Machines
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,214 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,617 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,300 questions
{count} votes

Accepted answer
  1. Naveen Kumar M 75 Reputation points
    2024-12-23T10:05:17.5033333+00:00

    Hello,

    This issue stems from changes in Microsoft’s email security policies. Microsoft has been deprecating Basic Authentication for SMTP and other protocols in favor of Modern Authentication (OAuth 2.0) to enhance security. This is why the error message states:

    "Authentication unsuccessful, basic authentication is disabled."

    Since the email functionality was working fine earlier, it suggests your setup was using Basic Authentication, which is no longer supported for Microsoft 365 or Outlook email accounts.

    Steps to Resolve the Issue

    1. Enable SMTP Authentication for the Mailbox

    Although Basic Authentication is deprecated, SMTP AUTH can still be enabled for accounts if needed (temporarily). Follow these steps:

    Log into Microsoft 365 Admin Center (admin credentials required):

    1. Navigate to Users > Active Users.
      1. Select the user account used for sending emails.
        1. Go to Mail > Manage email apps.
          1. Ensure Authenticated SMTP is enabled for the user account.
          Allow SMTP AUTH Globally (if disabled):
          1. In the Microsoft 365 Admin Center, go to Settings > Org settings.
            1. Select Modern Authentication.
              1. Enable Authenticated SMTP if it’s disabled globally.

    Note: Microsoft may still phase out SMTP AUTH entirely for new accounts in the future.

    1. Use an App Password

    If SMTP AUTH is enabled for the mailbox, you need to generate an App Password because Outlook and Microsoft 365 accounts no longer allow regular passwords for non-interactive logins (like SQL Server Database Mail).

    • Steps to generate an App Password:
      1. Go to your Microsoft account security settings: https://mysignins.microsoft.com/security-info
        1. Enable Two-Step Verification if not already enabled.
          1. Under Security Info, select App Passwords and create a password.
            1. Use this app password in your SQL Server Database Mail configuration.
    1. Modify SQL Server Database Mail Configuration

    After enabling SMTP authentication and generating an App Password:

    • Open SQL Server Management Studio (SSMS).
    • Go to Management > Database Mail.
    • Right-click and select Configure Database Mail.
    • Update the SMTP account details:
      • SMTP Server: smtp.office365.com
        • Port: 587 (TLS encryption) or 25.
          • SMTP Authentication: Use the App Password instead of your regular password.
            • Enable Secure Connection: Yes (TLS).
            • Test the configuration by sending a test email.
    1. Switch to OAuth 2.0 (Modern Authentication)

    If the above workaround does not work or SMTP AUTH is entirely disabled:

    • SQL Server Database Mail does not natively support OAuth 2.0. You would need to:
      • Use a middle layer application (e.g., a custom script or a mail relay server) that handles OAuth 2.0 token generation and sends emails through Microsoft’s API.
      • Alternatively, consider using Microsoft Graph API for sending emails, which supports Modern Authentication.

    Please let me know if any questions

    Kindly accept answer if it helps

    Thanks

    Naveen


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.