ShyProgrammer ShyProgrammer - 1 year ago 170
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;

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 Source

try setting the pickup directory manually:

// C#

client.PickupDirectoryLocation = ...;

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

            <smtp deliveryMethod="SpecifiedPickupDirectory">
                    pickupDirectoryLocation="..." />
                <network defaultCredentials="false" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download