I’ve been using the Smtp server 127.0.0.1 .The error I get:
System.Net.Mail.SmtpException: Cannot get IIS pickup directory.at System.Net.Mail.IisPickupDirectory.GetPickupDirectory().
This Error occured ,when Email send from ASP web page.But EMail send from ASP.NET page,error is not occurred. Plz help .
I was having this same error on Windows 7 with code that worked fine on XP. After much trial and error. I setup IIS to store mail in a pickup directory. But I still had the error.
In my code I commented out the line:
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
Removing this line of code worked, not sure why. Hope it works for you too because this issue is a real time waster to troublshoot.
I did NOT have to change any permissions on the directory. I did NOT have to modify the metabase. I did NOT have to modify the web.config (which I really didn't want to do because I only want the emails placed into a directory while I'm doing development on my local machine, not in production - I didn't want two different web.config files to maintain).
The pickup directory is stored in the II6 Metabase, so if the account that your web-app runs as does not have access to the required nodes, this error can be thrown (had this myself). Metabase permissions are seperate from file permissions, so you explore it with Metabase explorer:
http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&displaylang=en (its part of the IIS resource kit)
These nodes need to have read permission given to your web-app user: \LM\SmtpSvc \LM\SmtpSvc\1
You can also specify it for your unittest project:
And your test code:
Create the app.config file in your unittest project if not exists or merge these lines with existing app.config.
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 missing IIS SMTP service.
If you are sending mail using System.Net.Mail.SmtpClient, try setting the pickup directory manually:
Or set this in ASP.NET's Web.config instead:
Alternatively, use
SmtpDeliveryMethod.Network
method instead and sent theHost
andPort
properties to your SMTP server.More information: http://forums.iis.net/p/1149338/1869548.aspx