C# app sending email from Outlook 365 account, error "5.7.57 Client not authenticated to send mail"

Tim Ammons 25 Reputation points
2024-02-01T15:51:07.7433333+00:00

I have a C# application (.NET 4.8) that sends email from an Outlook 365 mailbox, and here is some code I'm using:

2024-02-01_10-56-24


I am getting the following error: System.Net.Mail.SmtpException: '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, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [MN2PR14CA0001.namprd14.prod.outlook.com 2024-01-31T14:51:46.902Z 08DC224A19943AD3]' SMTP is turned on for the sending email account.

I have triple-checked the email/password - I can login to outlook.office.com with the credentials I'm using.

Two Factor Authentication initially was turned "off" for the sending email account. Got the error above.

I also changed Two Factor to "on" and added an app password. Using the app password, got the same error.

I believe that Microsoft is still trying to "two factor" the account when my program tries to send mail from the account.

Ideas are welcome.

Microsoft 365 and Office Install, redeem, activate For business Windows
Developer technologies .NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-02-02T02:34:44.92+00:00

    Hi @Tim Ammons ,Welcome to Microsoft Q&A,

    You can no longer use Basic Authentication to send SMTP emails through Office365, seehttps://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/deprecation-of-basic-authentication-exchange-online Try stopping using SMTP and switching to using the Graph API https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http

    Also try to authenticate your device or application directly with a Microsoft 365 or Office 365 mailbox, and send mail using SMTP AUTH client submission

    This option isn't compatible with Microsoft Security Defaults. We recommend using Modern Authentication when connecting with our service. Although SMTP AUTH now supports OAuth, most devices and clients haven't been designed to use OAuth with SMTP AUTH. As a result, there are no plans to disable Basic Authentication for SMTP AUTH clients at this time. For more information about OAuth, see Authenticate an IMAP, POP or SMTP connection using OAuth.

    You must also verify that SMTP AUTH is enabled for the mailbox being used. SMTP AUTH is disabled for organizations created after January 2020 but can be enabled per-mailbox. For more information, see Enable or disable authenticated client SMTP submission (SMTP AUTH) in Exchange Online. Best Regards, Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  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.

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tim Ammons 25 Reputation points
    2024-02-06T17:07:09.22+00:00

    @Anonymous Thanks for your direction. I have been working on moving my app to Modern Auth. I did all the setup in Azure, including registering an app that has Mail.Send permissions, and as an Admin I consented. Then using Postman, I delivered mail with a client secret using the app registered in Azure. As a reminder, this is a C# console app (.NET 4.8). I imported Microsoft Graph into my project. Here is an excerpt from my code. When the SendMail line pointed to below executes, it does nothing - it does not produce an error and does not send an email. Any idea where I'm going wrong? User's image

    1 person found this answer 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.