send email from MVC 4 ASP.NET app
20,491
Solution 1
Best Idea to use SMTP mail functionality in .NET + MVC/ASP is this open source codeplex library:
Especially since the default-delivered components in .NET framework does fully support all types of SSL/TSL etc. (implicit/explicit mode as keyword here)
Solution 2
From a quick look you haven't set up the "From" property.
var mailMessage = new MailMessage();
mailMessage.To.Add("[email protected]");
mailMessage.From = new MailAddress("[email protected]");
mailMessage.Subject = "testing 2 ";
mailMessage.Body = "Hello Mr. Aderson";
mailMessage.IsBodyHtml = false;
Author by
K.Z
Updated on February 23, 2020Comments
-
K.Z about 4 years
I am trying to setup simple but complete ASP.NET MVC 4 web app, where I can send email to specific address, I configure the web.config file for SMPT settings and code in controller call, but I am getting error message "The SMTP host was not specified"
<system.net> <mailSettings> <smtp deliveryMethod="Network" from="[email protected]"> <network host="smtp.live.com" port="25" userName="[email protected]" password="myPassword" defaultCredentials="true"/> </smtp> </mailSettings>
in controller class
var mailMessage = new MailMessage(); mailMessage.To.Add("[email protected]"); mailMessage.Subject = "testing 2 "; mailMessage.Body = "Hello Mr. Aderson"; mailMessage.IsBodyHtml = false; var smptClient = new SmtpClient { EnableSsl = false }; smptClient.Send(mailMessage);
many thanks