为什么我尝试使用actionmailler向我的电子邮件地址发送电子邮件失败?
我的代码和配置有什么问题?
配置
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="myemail@gmail.com">
<network host="smtp.gmail.com" userName="myemail@gmail.com" password="fakepass" port="587"/>
</smtp>
</mailSettings>
</system.net>
邮件控制器
public class MailController:MailerBase {
public EmailResult SampleEmail(EmailModels model)
{
From = "myemail@gmail.com";
To.Add(model.Email);
Subject = "test";
return Email("SampleEmail",model);
}
发送电子邮件方式
public ActionResult SendEmail()
{
var user = new EmailModels
{
FirstName = "send_email",
Email = "send_email@gmail.com"
};
new MailController().SampleEmail(user).DeliverAsync();
return View();
}
答案 0 :(得分:1)
写下这个:
<network enableSsl="true" host="smtp.gmail.com" userName="myemail@gmail.com" password="fakepass" port="587"/>
取代:
<network host="smtp.gmail.com" userName="myemail@gmail.com" password="fakepass" port="587"/>