5.7.57 SMTP - Client was not authenticated to send anonymous mail during MAIL FROM error
You seem to be passing the From
address as emailAddress
, which is not a proper email address. For Office365 the From
needs to be a real address on the Office365 system.
You can validate that if you hardcode your email address as the From
and your Office 365 password.
Don't leave it there though of course.
C# SMTP MailMessage receiving error 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
I found an example code block elsewhere on this site and replacing everything I had with it made the difference.
The function name and parameters were the same, but here's what I replaced the body of it with.
var _mailServer = new SmtpClient();
_mailServer.UseDefaultCredentials = false;
_mailServer.Credentials = new NetworkCredential("my email", "my password");
_mailServer.Host = "smtp.office365.com";
_mailServer.TargetName = "STARTTLS/smtp.office365.com";
_mailServer.Port = 587;
_mailServer.EnableSsl = true;
var eml = new MailMessage();
eml.Sender = new MailAddress("my email");
eml.From = eml.Sender;
eml.To.Add(new MailAddress(to));
eml.Subject = subject;
eml.IsBodyHtml = (bodyType == BodyType.HTML);
eml.Body = body;
_mailServer.Send(eml);
I don't know for certain but I think that replacing the Host value with the smtp Office 365 link rather than an outlook one, as well as remembering to add a Target Name which I did not have before, both did the trick and solved the authorization issue (I had previously confirmed it wasn't a credentials issue with our tech support).
Related Topics
Copy Files from Resources/Streamingassets to Application.Persistentdatapath Upon Installation
A Method for Making Http Requests on Unity iOS
Simple iOS Bluetooth Data Transmission Using Unity
What Is a Dynamic Language, and Why Doesn't C# Qualify
Operators as Method Parameters in C#
Good Resource to Learn Bdd, Tdd (Ruby , C#, JavaScript)
Signalr(V2.2.0) Ondisconnected Set User Offline
Arkit Body Tracking Using Xamarin and C# Inaccurate
Does C# Have an Equivalent to JavaScript's Encodeuricomponent()
Understanding Floating Point Problems
How to Flatten an Expandoobject Returned via JSONresult in ASP.NET MVC
Handling Decimal Values in Newtonsoft.JSON
C# Webbrowser Control -- Get Document Elements After Ajax
Read and Write File on Streamingassetspath
How to Install Android APK from Code in Unity
Specified Argument Was Out of the Range of Valid Values. Parameter Name: Site
Debugging Automatic Properties
Automapper: Update Property Values Without Creating a New Object