请求获得类型&System; System.Net.Mail.SmtpPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'失败

时间:2014-07-17 12:49:22

标签: c# asp.net asp.net-mvc smtp

Iam在ASP.NET MVC 4中有一个邮件表单,可以在本地运行,但不能直播。我收到了你在标题上看到的错误,这是我的代码。

这是我的Web.config代码:

<system.net>
<mailSettings>
  <smtp deliveryMethod="Network">
    <network
      host="smtp.mandrillapp.com"
    />
  </smtp>
</mailSettings>

这是我的控制器代码:

    [HttpPost]
    public ActionResult Contact(SendMail input)
    {
        ViewData["Message"] = "Success";
        var space = " ";

        MailMessage mail = new MailMessage();
        mail.From = new MailAddress("no-reply@wideart.se");
        mail.To.Add("info@wideart.se");
        mail.Subject = "Intresse!";
        mail.Body = "Name: " + input.Name + space + "Email: " + input.Email + space + "Number: " + input.Number + space + "Message: " + input.Message;
        mail.IsBodyHtml = true;

        SmtpClient smtp = new SmtpClient("smtp.mandrillapp.com");
        smtp.Port = 587;
        smtp.Credentials = new NetworkCredential("info@wideart.se", "gDKFpiiWhLSqVTMNzL4nDw");

        try
        {
            smtp.Send(mail);
        }
        catch (Exception ex)
        {
            Response.Write("Error: " + ex.ToString());
        }

        return View();
    }
}

我尝试使用port =&#34; 25&#34;和港口=&#34; 587&#34;在网络代码上,但我也有错误。

我需要帮助!

0 个答案:

没有答案