本文介绍了申请类型的权限'System.Net.Mail.SmtpPermission,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089'失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有荫ASP.NET MVC 4在本地工作,但不是生活在一个邮件形式。我得到它,你可以在标题看到的错误,这里是我的code。

Iam having a mail form within ASP.NET MVC 4 that works locally but not live. I get the error which you can see on the title, here is my code.

这是我的web.config code:

This is my Web.config code:

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

这是我的控制器code:

This is my Controller code:

    [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();
    }
}

我尝试使用端口=25和端口=网络上的code587,但我得到了一个错误出现以及。

I tried using port="25" and port="587" on the network code, but I got an error there aswell.

我需要帮助!

推荐答案

我看你的code是正确的。什么是你看到错误消息?您可能需要联系您的托管服务提供商有关您需要使用SMTP细节

I see that your code is right. What is the error message that you see? You may need to contact your hosting provider about the smtp details that you need to use

这篇关于申请类型的权限'System.Net.Mail.SmtpPermission,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 13:07