Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while using Office365 SMTP in Asp.Net

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" />
like image 332
Ajmal VH Avatar asked Dec 10 '12 15:12

Ajmal VH


1 Answers

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
like image 140
Diego Farina Avatar answered Sep 30 '22 18:09

Diego Farina