1

当我从本地主机运行此联系我们页面时,它工作正常。

MailMessage msg=new MailMessage();
//Sender Email
msg.From = new MailAddress(TextBox1.Text);
//Reception Email
msg.To.Add("recieve@gmail.com");
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("abc@gmail.com", "password");
smtp.EnableSsl = true;
smtp.Send(msg);

但是当我托管网站时,它不起作用。这段代码有什么问题?

此代码在 localhost 上运行良好。

但是当它在互联网上托管时。这是发生的错误日志。

System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。在 System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net 的 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) 了解更多信息。 System.Net.Mail.SmtpClient.Send(MailMessage 消息)处的 Mail.SmtpTransport.SendMail(MailAddress 发件人,MailAddressCollection 收件人,字符串传递通知,布尔 allowUnicode,SmtpFailedRecipientException& 异常)

4

0 回答 0