简体   繁体   English

发送电子邮件不在本地工作

[英]sending email works locally not on server

Sending email works locally but when I upload my code to my server on bigrock it does not work. 发送电子邮件在本地工作,但当我将我的代码上传到bigrock上的服务器时,它不起作用。 I get this error. 我收到这个错误。

Error Request for the permission of type 'System.Net.Mail.Smtp Permission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 错误请求类型'System.Net.Mail.Smtp Permission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败。

My code: 我的代码:

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);

Make sure your Web.Config file has the trust level set to full 确保您的Web.Config文件的信任级别设置为完整

 <configuration>
  <system.web>
    .....
    <trust level="Full" originUrl=""/>
  </system.web>
</configuration>

you must set the following in System.Net.Mail.SmtpClient variable (eg *smtp *): 您必须在System.Net.Mail.SmtpClient变量中设置以下内容(例如* smtp *):

SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net", 25);

smtp.EnableSsl = false; smtp.EnableSsl = false; // check if your ISP supports SSL //检查您的ISP是否支持SSL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM