Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpecifiedPickupDirectory will not create files until viewed by a user on the server

Tags:

asp.net

iis

smtp

I'm using a "trick" (nicely described here) to store my emails on the application server during testing.

My config file looks like this:

<system.net>  
    <mailSettings>    
        <smtp deliveryMethod="SpecifiedPickupDirectory" from="[email protected]">      
            <specifiedPickupDirectory pickupDirectoryLocation="E:\EmailStore" />    
        </smtp>  
    </mailSettings>
</system.net>

The directory exists and it has no rights issues.

Here is the problem. The files won't be created until I navigate to the folder on the server. Then all of a sudden bang all the files are poping into the directory.

Anyone have any idea what is going on?

I've noticed there is another choice - PickupDirectoryFromIis -- but I'm unclear when I should use SpecifiedPickupDirectory and when I should use PickupDirectoryFromIis.

What is the difference between SpecifiedPickupDirectory and PickupDirectoryFromIis? When should I use one over the other? Is this the cause of the files not appearing till I navigate?

like image 994
Hogan Avatar asked Dec 07 '11 19:12

Hogan


1 Answers

This was a project that was migrated from ASP.NET 3.5 to ASP.NET 4.0

It seems that System.Net.Mail.SmtpClient now implements IDisposable. Change the code to use the following pattern seems to have solved the problem.

Best guess as to cause was the GC was not being called and the file buffer was not being flushed.

using (System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage())
{
   using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient())
   {
      // code
   }
}
like image 89
Hogan Avatar answered Nov 14 '22 21:11

Hogan