发送电子邮件在本地有效,但是当我将代码上传到bigrock上的服务器时,它不起作用。我收到此错误。
对类型为“ System.Net.Mail.Smtp权限,系统,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089”的权限的错误请求失败。
我的代码:
mm.Subject = "Nomination Received";
mm.Body = str.ToString();
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("abc@gmail.com", "password");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
答案 0 :(得分:0)
确保您的Web.Config文件的信任级别设置为完全
<configuration>
<system.web>
.....
<trust level="Full" originUrl=""/>
</system.web>
</configuration>
您必须在System.Net.Mail.SmtpClient变量(例如* smtp *)中设置以下内容:
SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net", 25);
smtp.EnableSsl = false; //检查您的ISP是否支持SSL