5.7.57 Smtp - Client Was Not Authenticated to Send Anonymous Mail During Mail from Error

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



Leave a reply



Submit