9

I am using Office365 web app SMTP to send email from Asp.Net but Its always throwing 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.1 Client was not authenticated at System.Net.Mail.MailCommand.CheckResponse

The web.config is given below - with username & password changed

<network enableSsl="true"  host="pod51007.outlook.com" userName="XXXX" password="XXXXX" port="587" defaultCredentials="false" />
Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Ajmal VH
  • 1,691
  • 1
  • 13
  • 27
  • @Sandra Walters You should really convert this comment into an answer as it's how I solved my problem with the above error. I wish I could up-vote it as it deserve. – DavRob60 Apr 18 '13 at 18:46

2 Answers2

3

I had the same problem and solved so:

Dim client As SmtpClient = New SmtpClient()
client.Credentials = New System.Net.NetworkCredential("your user", "your password")
client.Port = 587 
client.Host = "smtp.office365.com"

important are this instruction, without them is not working :

client.UseDefaultCredentials = False
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.EnableSsl = True
Mike Szyndel
  • 10,461
  • 10
  • 47
  • 63
Diego Farina
  • 339
  • 2
  • 10
  • This was very helpful! If you need to enable SSL in web.config, enableSsl="true" will work in .NET 4 - found this on http://stackoverflow.com/a/4973831/908677 and it worked for me. – Elijah Lofgren Nov 13 '15 at 15:42
2

I think the error message is misleading (as with most Microsoft errors!) - The error code looks very simular to a SMTP error and 5.7.1 is a relay error. You may need to specify your development/production public IP address using the admin portal provided by Microsoft.

Matt
  • 2,691
  • 3
  • 22
  • 36