title: The server response was: 5.7.57 SMTP - Office 365
body: <p>Currently we have a web form that send's emails which has stopped working months back with the migration of Office 365 at our company. I have eliminated all other code while troubleshooting and just run email portion to get 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 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM ".</p>
  
  <p>I have found many solutions on the web/stack overflow with the same error code, tried changing the code to proposed solutions and have had no luck. </p>
  
  <p>Tried many different email aliases that are listed in our global address list with no luck for my account, different ports(25,587), different smtp addresses, and have had no luck so far.</p>
  
  <p>Multiple users are stating "This code unfortunately is no longer valid with Office 365. Error message that comes up is 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 [HE1PR05CA0133.eurprd05.prod.outlook.com] " on the article linked below.</p>
  
  <p><a href="https://stackoverflow.com/questions/6244694/send-smtp-email-using-system-net-mail-via-exchange-online-office-365">Send SMTP email using System.Net.Mail via Exchange Online (Office 365)</a></p>
  
  <p>My code seen below.</p>
  
  <pre><code>    Dim mail As MailMessage = New MailMessage
      mail.From = New MailAddress("email12345@company.com")
      mail.To.Add("email12345@company.com")
      mail.Subject = "Test"
      mail.IsBodyHtml = False
      mail.Body = "Test"
  
      Dim SmtpServer As SmtpClient = New SmtpClient
  
      SmtpServer.Host = "smtp.office365.com"
      SmtpServer.Port = 587
      SmtpServer.UseDefaultCredentials = False
      SmtpServer.Credentials = New System.Net.NetworkCredential("MyEmail", "MyPass")
      SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network
      SmtpServer.EnableSsl = True
      SmtpServer.TargetName = "STARTTLS/smtp.office365.com"
      Try
          SmtpServer.Send(mail)
      Catch ex As Exception
          Response.Write(ex.ToString)
      End Try
  </code></pre>
  
  <p>As it seems this is happening to many people, I would like to know what they are doing to resolve it?</p>