ShyProgrammer
ShyProgrammer

Reputation: 95

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.

Upvotes: 1

Views: 2244

Answers (1)

Midhun Mundayadan
Midhun Mundayadan

Reputation: 3182

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> 

Upvotes: 1

Related Questions