为什么我尝试使用 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>
邮件控制器
公共类 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();
}