电子邮件无法使用actionmailler发送到电子邮件地址

时间:2013-06-26 02:47:56

标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

为什么我尝试使用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();
        }

1 个答案:

答案 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"/>