ShyProgrammer ShyProgrammer - 15 days ago 5
C# Question

SmtpException: Cannot get IIS pickup directory

I am trying to send email from my mvc application. Following is a part of the code I am using:

SmtpClient smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(message);


The above code is giving the error:


Cannot get IIS pickup directory SmtpException.


But if I run my Visual Studio as an Administrator, emails are sent successfully.

If I understand correctly, the issue is regarding access permissions, but I just can't figure out what.
If Relevant, the application is an intranet application with windows authentication.

Answer

try setting the pickup directory manually:

// C#

client.PickupDirectoryLocation = ...;

Or set this in ASP.NET's Web.config instead:

<configuration>
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="SpecifiedPickupDirectory">
                <specifiedPickupDirectory
                    pickupDirectoryLocation="..." />
                <network defaultCredentials="false" />
            </smtp>
        </mailSettings>
    </system.net>
</configuration> 
Comments