我正在使用 c# 发送电子邮件:
protected void SendEmailToVisitor(string Name, string Email, string Contact, string Message, string Subject)
{
string myEmail = ConfigurationManager.AppSettings["Email"];
MailMessage objMail = new MailMessage();
objMail.From = new MailAddress(myEmail);
objMail.Subject = "Chanderraj.com";
objMail.To.Add(Email);
objMail.IsBodyHtml = true;
StringBuilder emailMessage = new StringBuilder();
emailMessage.Append("<h2>Hi, "+Name+",</h2> <br/>");
emailMessage.Append("Thank you for writing us. <br/><br/><br/>");
emailMessage.Append("Best wishes from http://www.chanderraj.com");
objMail.Body = emailMessage.ToString();
SmtpClient objSmtpClient = new SmtpClient();
objSmtpClient.UseDefaultCredentials = false;
// objSmtpClient.EnableSsl = true;
objSmtpClient.Send(objMail);
this.Reset();
lblSent.Text = Name + ", your message sent.";
}
<system.net>
<mailSettings >
<smtp>
<network host="smtp.gmail.com" userName="chanderraj1989@gmail.com" enableSsl="true" password="xxxxxxxxxx" port="587" />
</smtp>
</mailSettings>
如果我在配置中添加 enableSsl,它会在页面加载之前显示配置错误:
无法识别的属性“enableSsl”。
这可能是由于服务器上的 .NET 版本较旧。
因此,我从配置中删除了 enablSsl 并将其放入代码中,然后显示:
SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。