Get IIS pickup directory location
If you plan to use local IIS SMTP service to send emails you created using Mail.dll, you’ll need to save those emails to IIS pickup folder.
Default folder location is “c:\Inetpub\mailroot\Pickup”
There is a way to get IIS pickup folder location directly from IIS metabase. To get this path programmatically we’ll use IisPickupDirectory class. Unfortunatelly this class is not public, we’ll use its name to get its type and Activator class to invoke private static method GetPickupDirectory.
To get type reference, we need to specify fully qualified type name “System.Net.Mail.IisPickupDirectory System, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089”. We can also search CurrentDomain’s assemblies to find System assembly and get its full name.
Assembly system = AppDomain.CurrentDomain.GetAssemblies() .First(x => x.GetName().Name == "System"); Type iisPickupType = Type.GetType( "System.Net.Mail.IisPickupDirectory, " + system.GetName().FullName, true); // -or- use fully qualified assembly name directly: //Type iisPickupType = Type.GetType( // "System.Net.Mail.IisPickupDirectory, " // + "System, Version=18.104.22.168, Culture=neutral, " // + "PublicKeyToken=b77a5c561934e089", // true); string pickupFolder = (string)iisPickupType.InvokeMember( "GetPickupDirectory", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, null);
“Cannot get IIS pickup directory.” error
Unfortunately, this exception is raised when any kind of problem occurs, while trying to determine the location of IIS/SMTP pickup directory.
A common cause is simply missing IIS SMTP service.
The pickup directory is stored in the IIS Metabase, so if the account that your web-app runs as does not have access to the required nodes, this error can be thrown. Metabase permissions are separate from file permissions, so you explore it with Metabase explorer (part of the IIS resource kit).
These nodes need to have read permission given to your web-app user: \LM, \LM\Smtpsrv\ and \LM\Smtpsrv\1