【发布时间】:2016-03-30 10:28:54
【问题描述】:
我检查了其他问题,并且能够解决我的代码中的一些错误,但是 smtp.Credentials = nc; (其中 nc 是我的网络凭据)抛出异常,请求操作在 MFE 代理上中止,SMTP 服务器是不可用。
请,任何帮助将不胜感激。下面是我的代码:
MailMessage msg = new MailMessage();
msg.From = new MailAddress("fromemail");
msg.To.Add("toemail");
msg.Subject = "Contact Us";
msg.Body = cname.Text + "sent me this message" + cmessage.Text + "with this email, " + email.Text;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential nc = new NetworkCredential();
nc.UserName = "fromemail";
nc.Password = "fromemailpwd";
smtp.Credentials = nc;
smtp.Port = 587;
smtp.Send(msg);
sPanel.Visible = true;
lblSuccess.Text = "Success! Thanks for contacting us, we will get back to you soon.";
我将smtp.Credentials = nc 更改为smtp.Credentials = new NetworkCredentials("fromemail", "fromemailpwd");
现在,正是这行 smtp.Send(msg) 引发了异常。
【问题讨论】:
标签: c# asp.net smtp gmail system.net.mail