SmtpClient.Send中的System.Security.SecurityException

时间:2015-12-03 09:11:35

标签: .net security

安全例外 说明:应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系或在配置文件中更改应用程序的信任级别。

异常详细信息:System.Security.SecurityException:请求类型为“System.Net.Mail.SmtpPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089”的权限失败。

webconfig

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

SmtpClient sc_mail = new SmtpClient();
            sc_mail.Host = "***";
            sc_mail.Port = 25;
            sc_mail.Credentials = new System.Net.NetworkCredential("***", "****");
            sc_mail.EnableSsl = true;
            sc_mail.UseDefaultCredentials = false;
            MailMessage mesaj = new MailMessage();
            MailAddress fromAddress = new MailAddress("***");
            mesaj.From = fromAddress;
            mesaj.To.Add("***");
            mesaj.Subject = "İletişim Formu";
            mesaj.IsBodyHtml = true;
            mesaj.Body = "Ad Soyad: " + name.Value + "<br />Yaşadığınız Şehir: " + city.Value + "<br />Telefon: " + phone.Value + "<br />E-Posta: " + email.Value + "<br />Notlar: " + comment.Value;
            sc_mail.Send(mesaj);
        }
        else
            buttonblue.Value = "Gizlilik Sözleşmesi!!!";

1 个答案:

答案 0 :(得分:0)

尝试禁用属性“EnableSsl”,它可能会像那样......