2

I am a corporate employee. As part of my work I need to send emails from my C# code.

With the below code I am able to send emails successfully using less secure gmail ID. But I am not able to do same with my corporate outlook exchange based email ID. I get below exception.

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, SmtpClientAuthentication is disabled for the Mailbox. Visit https://aka.ms/smtp_auth_disabled for more information. [BN9PR03CA0659.namprd03.prod.outlook.com]"

what I should do ? is there a way I can make my corporate outlook exchange email ID less secure to enable to sending emails. (Like I did for gmail.)

below is the code I am using.

        MailMessage message = new MailMessage(from, to);
        string mailbody = "In this article you will learn how to send a email using Asp.Net & C#";
        message.Subject = "Sending Email Using Asp.Net & C#";
        message.Body = mailbody;
        message.BodyEncoding = Encoding.UTF8;
        message.IsBodyHtml = true;         
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;
        client.Credentials = new NetworkCredential("name@corporatecompany.com", "$password");            
        client.Host = "smtp.office365.com";
        client.Port = 587;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;          
        try
        {
            client.Send(message);
        }
Kᴀτᴢ
  • 2,146
  • 6
  • 29
  • 57
Krishna Prasad
  • 21
  • 1
  • 1
  • 2
  • You need to make sure the smtp address is correct. It may be different for your org although using O365 and may be port#. Check with your corporate Email managing team/AD team whoever is responsible for this and try again. – Ak777 Jan 12 '22 at 04:52
  • Does this answer your question? [5.7.57 SMTP - Client was not authenticated to send anonymous mail during MAIL FROM error](https://stackoverflow.com/questions/30342884/5-7-57-smtp-client-was-not-authenticated-to-send-anonymous-mail-during-mail-fr) – Eugene Astafiev Jan 12 '22 at 11:52
  • There are a bunch of similar posts here. Have you checked existing posts with the same error message at SO? – Eugene Astafiev Jan 12 '22 at 11:53

2 Answers2

1

https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission Use the Microsoft 365 admin center to enable or disable SMTP AUTH on specific mailboxes

  1. Open the Microsoft 365 admin center and go to Users > Active users.
  2. Select the user, and in the flyout that appears, click Mail.
  3. In the Email apps section, click Manage email apps.
  4. Verify the Authenticated SMTP setting: unchecked = disabled, checked = enabled.
  5. When you're finished, click Save changes.
tryNsee
  • 11
  • 1
0

You need to make sure the smtp address is correct. It may be different for your org, although using O365 and may be port#. Check with your corporate Email managing team/AD team whoever is responsible for this and try again.

It may be that the smtp host can be your org domain host instead of generic one. I am suggesting based on experience of what we have, as we also use O365 for our corporate emails and I have our smtp host as "mail..com" with port#. And there could be a service account which has given appropriate permissions to use as otherwise, it would become less secure to use the smtp relay.

Ak777
  • 346
  • 7
  • 18
  • OP said the code works when using OP's credentials, so smtp address must be correct. – Bohemian Sep 20 '22 at 22:07
  • Please read his statement, it states, his code works when he uses less secure gmail creds which is NOT corporate account creds. And thats where my recommendation is to reach out to his Email/Office 365 mgmt. team who may provide options/details to use theirs as SMTP. ```With the below code I am able to send emails successfully using less secure gmail ID``` – Ak777 Sep 21 '22 at 03:43