SMTP windows server 2008 Asp.net Pickup Directory - asp.net

I have configured an smtp server over a IIS 6.0 in windows server 2008.
I have already granted:
-Administrators
- NT AUTHORITY\LOCAL SERVICE
- NT AUTHORITY\NETWORK SERVICE
- IUSR_MACHINE_NAME
- MY Domain User
The folder structure for the SMTP service is the following:
- Badmail
- Drop
- Pickup
- Queue
I have a mvc application that send emails via pickup directory, the configuration is the following:
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="E:\Email\dev\Pickup" xdt:Transform="Replace" />
</smtp>
the problem is when I set up the pickup directory the application never writes the email files to that specific folder, the odd thing is that I'm not getting any exception either, I guess this could be an issue related to some user permissions but I already have granted the full control to everyone in that folder as well.
The fact is that I'm not getting get any email.
this environment isn't for production, and is just for testing purposes,
Any Advice?

Try below code, this works for me, I have been using it in my project and when sending mail, the eml file gets created here.
<system.net>
<mailSettings>
<!-- Method#2: Dump emails to a local directory -->
<smtp from="admin#abc.com" deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" />
<specifiedPickupDirectory pickupDirectoryLocation="F:\Project\Mails\" />
</smtp>
</mailSettings>
</system.net>

Related

Google Email Client using .Net framework 4.0

I have created a gmail client using host as smtp.gmail.com and configures all the requires credentials and settings.
I have tested the client by hosting it in my local IIS. It worked great.
Then I hosted the project on public server and tested the client. here I am facing the problem that google stopping the signin and i received a mail saying that "Suspicious sign in prevented".
I have given a strong password and fully qualified email address. still I am getting the same problem.
what might be the cause for problem ?
here is my config file.
<?xml version="1.0"?>
<configuration>
<system.net>
<mailSettings>
<smtp from="xxxxxxxxxx#gmail.com">
<network defaultCredentials="false" host="smtp.gmail.com" port="587" userName="xxxxxxxxxxx#gmail.com" password="xxxxxxxxx" enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
<system.web>
<compilation debug="false" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
</configuration>
thanks in advance

How can I change IIS 7 server-wide SMTP settings for .NET 4

I'm trying to configure the IIS 7 SMTP settings for .NET 4 web applications, so all sites use the same host. I've configured the host for the server inside the IIS manager, but this is only picked up by .NET 2 web apps.
.NET 4.0 applications don't pickup the host.
Is there a way to specify a machine-wide SMTP setting for .NET 4? The server is x64.
I discovered the answer: you need to add the <system.net> section to your machine.config file, for the framework, e.g.
<system.net>
<mailSettings>
<smtp from="blah#blah">
<network host="123.321.123.321" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
IIS7 stores its SMTP settings in the metabase.xml file still, however you can configure it for a framework via the machine.config as that takes precedence.
You just need to remember that if you're on 64 bit server, the path is
C:\Windows\Microsoft.NET\Framework64

System.Net.Mail.SmtpException: Cannot get IIS pickup directory

Fellas,
Getting the "Cannot get IIS pickup directory" exception with my app. I have my directory created and specified in the config as follows:
<system.net>
<mailSettings>
<smtp deliveryMethod="PickupDirectoryFromIis" from="donotreply#mysite.com">
<specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\email\mysite"/>
</smtp>
</mailSettings>
</system.net>
Trying to have the emails placed locally in a directory so I can see them.
Any ideas why it could be throwing that exception?
FWIW, this is IIS7 + Windows 7 and an MVC2 app (C#).
Also, went ahead and gave permissions to the IIS_IUSRS group to that directory.
All,
Seems like I was using the wrong smtp deliveryMethod. I got the PickupDirectoryFromIis and SpecifiedPickup deliveryMethod's mixed up, and hence was using the wrong settings for it.

How do I set up smtp on Vista so I can use System.Net.Mail from local picup directory?

I've tried using the below solution (also found here: How do I set up smtp on Vista so I can use System.Net.Mail?) but I receive "Cannot get IIS pickup directory". I know I am pointing to an existing directory and my web.config are set up correctly, are there permissions I need to set up on the directory before I can write to it?
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory
pickupDirectoryLocation="c:\maildrop"/>
</smtp>
</mailSettings>
Have you checked the file permissions on the maildrop folder? You can enable write for all users and see if that works. If you just want IIS to write to it, I think the user is ASPNET, but I might be wrong on that.
Also this answer seems to show a "\" at the end of the directory path (I would hope asp.net would understand that though)

Storing SMTP outside the Web.Config File

For some time now I've been storing my connection and app settings in an external file and just referencing that file via my web.config. This works really well because it allows me to keep separate connection strings and app settings. This is really handy since I find during development I will often make many changes to the webconfig and I hate having to manage the environment specific values every time I need to update my web.config.
Is there anyway I can achieve this with he SMTP configuration sections in the web.config.
Sure, you can use the configSource attribute.
Example:
<system.net>
<mailSettings>
<smtp configSource="MailSettings.config"/>
</mailSettings>
</system.net>
Then put your mailSettings configuration data in MailSettings.config
So then your MailSettings.config file would have something like:
<network
host="relayServerHostname"
port="portNumber"
userName="username"
password="password" />
Update: looks like it may need to actually go in the smtp node to work properly, so I've updated the above code to indicate that - same idea, only this one should work. :)
I'm not sure if what I have here is only for newer versions of .NET. I got a runtime error using the accepted answer.
Please update the accepted answer with the code block below if working with newer versions of .NET. The smtp node should also be in the separate file - not just the network node. The whole smtp node in the actual Web.config file is replaced by the file you put there - unlike in the appSettings where it seems to add to it.
Web.config -
<system.net>
<mailSettings>
<smtp configSource="your-source-file">
</smtp>
</mailSettings>
</system.net>
Your file -
<smtp from="noreply#example.com">
<network
host="your-host"
port="your-port"
userName="your-user-name"
password="your-password"/>
</smtp>
My software stores it in the registry, even in production.

Resources