我检查了其他问题,并且能够解决我的代码中的一些错误,但是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)
即抛出异常。
我无法获得与您看到的相同的错误消息,但请查看此答案:MFE代理上的请求操作已中止,SMTP服务器不可用
但是,我确实知道Gmail需要EnableSSL = True
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句