1
votes

I need to use a company shared account (email address is removed for privacy) to send notifications, but fails all the time. I tried all possible codes with no luck.

So, I had a little suspicious about the account. Then I used my office 365 work account, and it is working as expected. But I still need to use the shared account.

The error information is as follows:

Message = "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [D*******8.na***11.prod.outlook.com]"

var message = new MailMessage("from", "to", "MySubject", "MyBody");
SmtpClient client = new SmtpClient("outlook.office365.com"); 
client.EnableSsl = true; 
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network; 
client.UseDefaultCredentials = false; 
client.Credentials = new NetworkCredential("username", "password");
client.Send(message);
1
My advice is to try to double check (I think you all ready done it) the server and such if are correct, if it is try to send the email from another PC that is in another place to see if it send it or not. I did have and still have a similar problem, on Angola the email account doesn't work and from my PC at work (Portugal) works at 100%, even did make a program to test, I press to button on the PC on Angola (Remote Desktop) then on my PC (like 4 seconds from each click) and from my PC is send and on the PC on Angola it doesn't sendCamadas
Thanks for your response. Actually, I have cross verified username, password, server etc and it's all correct. Also, I have verified with the different environment and the same behavior. The thing which I want to highlight is it works with any of the user accounts but not with service/shared account. I am trying to see if there is any specific permission required for the service account. Apparently, there is documentation for the same.user10251214

1 Answers

0
votes

If your account has multi-factor authentication enabled you'll need to use an "app password" for your Office 365 account instead of a regular one that you use to log on.

See https://docs.microsoft.com/en-us/azure/active-directory/user-help/multi-factor-authentication-end-user-app-passwords for how to set one up.