SmtpClient deliveryMethod

来源:互联网 发布:免费资源的电视软件 编辑:程序博客网 时间:2024/06/17 00:12

http://bartwullems.blogspot.sg/2010/02/smtpclient-deliverymethod.html

SmtpClient deliveryMethod

One of the nice but little known possibilities of the System.Net.Mail.SmtpClient class is the ability to drop emails into a location on disk. This makes it very easy to test your code without the need of an SMTP server.

Update your app.config or web.config like this:

   1:  <system.net>
   2:    <mailSettings>
   3:      <smtp deliveryMethod="SpecifiedPickupDirectory">
   4:        <specifiedPickupDirectory pickupDirectoryLocation="c:\mails\"/>
   5:      </smtp>
   6:    </mailSettings>
   7:  </system.net>


You can also configure this setting on the class itself. Files are dropped on the specified location and can be opened using Outlook Express or Windows Mail.