Given the following section in Web.Config
:
this is a configuration that worked perfectly for me:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="my-email@gmail.com">
<network defaultCredentials="false" host="smtp.gmail.com" port="587" userName="my-username" password="my-password"/>
</smtp>
</mailSettings>
</system.net>
there is no way to add the SSL parameter to the network tag. You will have to set it from code:
var smtpClient = new SmtpClient();
smtpClient.EnableSsl = true;
smtpClient.Send(message);
If you don't want to send the emails out using an external smtp, you can configure it to use the localhost and use a desktop email receiver like PaperCut (http://papercut.codeplex.com/). This is the config to achieve that:
<system.net>
<mailSettings>
<smtp>
<network host="127.0.0.1" port="25" />
</smtp>
</mailSettings>
</system.net>
Hope this helps!
There is no way to specify whether a SSL / Secure connection should be used when defining the mail settings in the web config file.
I'm pretty sure that's why you get an error.
One way to solve that is to create your own mail sending wrapper, and then using it in your application, but you probably already got that :)
It gets more complicated when using the .net membership controls, like forgot password, create user etc. A way to solve that, is to override the SendingMail event, and then set the EnableSSL property of the mailclient to true.
I hope i was able to help :)
For googlers ending up here, the correct way to do this is:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="SomeWebsite Admin <someuser@gmail.com>">
<network host="smtp.gmail.com" port="587" enableSsl="true" defaultCredentials="false" userName="someuser@gmail.com" password="somepassword" />
</smtp>
</mailSettings>
</system.net>
And your code is then:
smtp = new SmtpClient();
smtp.Send( mailMessage );
I think this part should be <smtp deliveryMethod="Network" from="SomeWebsite Admin <someuser@gmail.com>"> Like this <smtp deliveryMethod="Network" from="someuser@gmail.com">
If you're using 2-step verification, don't forget to generate an application specific password and use that, not the password you use to log on to Gmail.
(Sorry I can't add this as a comment. Not enough rep at the time of posting this.)
I am not familiar with working this way but in the web.config defaultCredentials is true, you set it to false when doing it programatically is that the difference?