asp.net – 在测试期间如何使电子邮件到本地文件夹?

前端之家收集整理的这篇文章主要介绍了asp.net – 在测试期间如何使电子邮件到本地文件夹?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何测试发送电子邮件从我的应用程序,而不会洪水我的收件箱?

有没有办法告诉IIS / ASP.NET如何将电子邮件发送到本地文件夹进行检查?

解决方法

是的,有一种方法.

You can alter web.config like this so
that when you send email it will
instead be created as an .EML file in
c:\LocalDir.

<configuration>  
     <system.net>    
      <mailSettings>      
       <smtp deliveryMethod="SpecifiedPickupDirectory">        
        <specifiedPickupDirectory pickupDirectoryLocation="c:\LocalDir"/>      
       </smtp>    
      </mailSettings>  
     </system.net>
    </configuration>

如果您不想/不能更改web.config,也可以使用相同的设置创建SmtpClient类的实例.在C#中看起来像这样:

var smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
var emailPickupDirectory = HostingEnvironment.MapPath("~/EmailPickup");
if (!Directory.Exists(emailPickupDirectory)) { 
    Directory.CreateDirectory(emailPickupDirectory)
}
smtpClient.PickupDirectoryLocation = emailPickupDirectory;
原文链接:https://www.f2er.com/aspnet/249880.html

猜你在找的asp.Net相关文章