我正在尝试设置简单但完整的 ASP.NET MVC 4 Web 应用程序,我可以在其中将电子邮件发送到特定地址,我为 SMPT 设置和 Controller 调用中的代码配置 web.config 文件,但我收到错误消息“未指定 SMTP 主机”
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4924300c242820250921263d24282025672a26673c22" rel="noreferrer noopener nofollow">[email protected]</a>">
<network host="smtp.live.com" port="25" userName="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35584c7058545c59755d5a4158545c591b565a1b405e" rel="noreferrer noopener nofollow">[email protected]</a>" password="myPassword" defaultCredentials="true"/>
</smtp>
</mailSettings>
在 Controller 类中
var mailMessage = new MailMessage();
mailMessage.To.Add("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8cf5e3f9fec9e1ede5e0cce4e3f8e1ede5e0a2efe3a2f9e7" rel="noreferrer noopener nofollow">[email protected]</a>");
mailMessage.Subject = "testing 2 ";
mailMessage.Body = "Hello Mr. Aderson";
mailMessage.IsBodyHtml = false;
var smptClient = new SmtpClient { EnableSsl = false };
smptClient.Send(mailMessage);
非常感谢
最佳答案
在 .NET + MVC/ASP 中使用 SMTP 邮件功能的最佳想法是这个开源 Codeplex 库:
特别是因为.NET框架中默认提供的组件完全支持所有类型的SSL/TSL等(此处隐式/显式模式作为关键字)
关于c# - 从 MVC 4 ASP.NET 应用程序发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18978702/