Reputation: 95
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
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