Not work when hosting ASP.NET contact us page

370 views Asked by At

When I run this contact us page from localhost its work fine.

MailMessage msg=new MailMessage();
//Sender Email
msg.From = new MailAddress(TextBox1.Text);
//Reception Email
msg.To.Add("[email protected]");
msg.Subject=TextBox2.Text;

String body="Name: "+TextBox4.Text+"\n\nMessage:\n\t"+TextBox3.Text+"";
msg.Body=body;

//SMTP Server
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new NetworkCredential("[email protected]", "password");
smtp.EnableSsl = true;
smtp.Send(msg);

But when I host website, it doesn't work. What is wrong with this code?

This code work fine on localhost.

But when it host on internet. This is the error log occured.

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message)

0

There are 0 answers