I'm slightly baffled here - I'm receiving the following error:
The SMTP host was not specified.
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
smtpClient.Port = 587;
<smtp from="email@example.com" deliveryMethod="Network" >
<network host="smtp.gmail.com" defaultCredentials="true"
port="587" enableSsl="true" userName="firstname.lastname@example.org"
public ActionResult SubmitFeature(FormData formData)
SmtpClient smtpClient = new SmtpClient();
MailMessage mail = new MailMessage();
mail.Body = "Test";
In a clean MVC project, I am unable to replicate your issue. Following the ScottGu blog post here, I was able to get a gmail sent email without issue (VS 2013, .NET 4.5.1, MVC 5). Note the the
<system.net> element is a top level element and not nested inside of
There are a few web.config files in your solution, ensure that the
mailSettings is inserted into the root level web.config (and not the one located in the Views folder)
<configuration> <system.net> <mailSettings> <smtp from="myEmail@gmail.com"> <network host="smtp.gmail.com" port="587" enableSsl="true" userName="myEmail@gmail.com" password="SuperSecretPwd" defaultCredentials="false" /> <!--This must be false on Gmail--> </smtp> </mailSettings> </system.net> </configuration>
var smtpClient = new SmtpClient(); var msg = new MailMessage(); msg.To.Add("MyOtherAddress@yahoo.com"); msg.Subject = "Test"; msg.Body = "This is just a test email"; smtpClient.Send(msg);
It is unclear if some of the extra attributes you have included are causing issues (thought they shouldn't) such as delivery method. Also, is there a setting for allowing SMTP access or is that just for IMAP/POP delivery?
If you can test and are successful in a clean project, then this would point to either a web.config transformation problem or some other setting(s) in your project overriding the web.config settings that you have in place.