如何在测试期间将电子邮件发送到本地文件夹?

时间:2023-01-15 09:22:39

How can I test sending email from my application without flooding my inbox?

如何测试从我的应用程序发送电子邮件而不会充斥我的收件箱?

Is there a way to tell IIS/ASP.NET how to deliver email to a local folder for inspection?

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

2 个解决方案

#1


35  

Yes there is a way.

是的,有办法。

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.

您可以像这样更改web.config,这样当您发送电子邮件时,它将被创建为c:\ LocalDir中的.EML文件。

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

You can also create an instance of the SmtpClient class with these same settings, if you don't want to/can't change the web.config. In C# that looks something like this:

如果您不想/不能更改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;

#2


1  

Configure rules in your email client to move the messages based on the subject/sender's email address?

在电子邮件客户端中配置规则以根据主题/发件人的电子邮件地址移动邮件?

#1


35  

Yes there is a way.

是的,有办法。

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.

您可以像这样更改web.config,这样当您发送电子邮件时,它将被创建为c:\ LocalDir中的.EML文件。

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

You can also create an instance of the SmtpClient class with these same settings, if you don't want to/can't change the web.config. In C# that looks something like this:

如果您不想/不能更改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;

#2


1  

Configure rules in your email client to move the messages based on the subject/sender's email address?

在电子邮件客户端中配置规则以根据主题/发件人的电子邮件地址移动邮件?