2011-03-08 83 views
1

我目前正在研究一个MVC原型,其中我想编译并使用物理SMTP服务器将电子邮件从表单发送到目录作为eml文件。虽然这不是关键的问题已引起了我的好奇心,以“为什么它不工作”在ASP.NET MVC应用程序中被忽略的smtp服务器

在我的web.config文件中,我有以下设置

<system.net> 

<mailSettings> 
    <smtp deliveryMethod="SpecifiedPickupDirectory"> 
    <network host="ignored"/> 
    <specifiedPickupDirectory pickupDirectoryLocation="c:\email" /> 
    </smtp> 
</mailSettings> 

但是我网内应用程序,每当我调用我的sendmail方法我收到一个异常,找不到smtp主机。我期望的是,smtpClient会生成地区的eml文件。或者我完全错过了SpecifiedPickupDirectory的要点,我不得不调用一个到smtp服务器的旅程?

在此先感谢

回答

1

下工作好了,我(我有没有SMTP服务器本地安装):

  1. 创建一个使用默认模板
  2. 一个新的ASP.NET MVC 2项目

    在web.config中提出:

    <system.net> 
        <mailSettings> 
         <smtp deliveryMethod="SpecifiedPickupDirectory"> 
          <network host="ignored"/> 
          <specifiedPickupDirectory pickupDirectoryLocation="c:\email" /> 
         </smtp> 
        </mailSettings> 
    </system.net> 
    
  3. 在的Index行动地说:

    public ActionResult Index() 
    { 
        // If you are using .NET 3.5 or earlier the 
        // SmtpClient class doesn't implement IDisposable 
        // so you might need to remove the "using" statement 
        using (var client = new SmtpClient()) 
        { 
         var mailMessage = new MailMessage("[email protected]", "[email protected]"); 
         mailMessage.Body = "Hello World"; 
         client.Send(mailMessage); 
        } 
        return View(); 
    } 
    
  4. 在运行中生成的EML文件的应用程序

  5. :\电子邮件
相关问题