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
Related
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>
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
should I stored my global WebMail variables within Application_Start() event? I read creating a Base Controller is not necessary, and it makes sense because I have used hooks in MVC architecture before. Is there a way I can simply hook these in?
e.g. WebMail.SmtpServer, WebMail.UserName, WebMail.Password, WebMail.From?
How about in the web.config
<system.net>
<mailSettings>
<smtp>
<network
host="myHost"
port="myPortNumber"
userName="username"
password="password" />
</smtp>
</mailSettings>
</system.net>
I have a doubt in my web application can i place two nework tags in smtp mailSetting tag.
I PLACED in SMTP two network tags , BUT WHEN I AM SENDING MAIL I AM GETTING THIS ERROR. The element may only appear once in this section. (C:\Inetpub\vhosts\example.com\httpdocs\web.config line 64)
THIS IS MY WEB CONFIG CODE ......
<system.net>
<mailSettings>
<smtp>
<network host="webmail.example.com" port="25" userName="info#example.com" Password="asdf" defaultCredentials="false"/>
<network host="webmail.yyy.com" port="25" userName="info#yyy.com" Password="asdf254" defaultCredentials="false"/>
</smtp>
</mailSettings>
You can use the AppSettings section and add as many configuration values as you like. You can use for example:
<appSettings>
<add key="SMTP1" value="smtpserver1"/>
<add key="SMTP2" value="smtpserver2"/>
<add key="SMTP3" value="smtpserver3"/>
<add key="SMTP4" value="smtpserver4"/>
</appSettings>
and then in your code decide which server to use.
Nope you cannot. Though you can carry as many details in AppSettings section.
The SMTP details section is used to specify default values. To have more than one you need to write some code to read your own custom values from appsessings or even implement your own config section.
If you want different settings for different deployment configurations I would use Web.config Transformation. It was introduced in ASP.NET 4.0.
You can have one default setting for when you build the project on your localhost and when you publish it to the server, another one will be used.
Reference:
http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx
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.