0

我有一个 MVC Razor Web 应用程序,它有一个反馈表和一个数据库后端。

当我完成反馈表并单击提交时,信息将进入数据库。

我的问题是如何将此信息通过电子邮件发送到电子邮件地址,代码如下:

[HttpPost]
        public ActionResult Feedback(FeedbackModel model)
        {
            if (ModelState.IsValid)
            {
                if (this.db.InsertFeedback(model))
                {
                    return RedirectToAction("FeedbackSuccessful");
                }
                else
                {
                    ModelState.AddModelError("", "Error! We were unable to process your feedback at this time. Please try again later.");
                }
            }
            return View(model);
        }
4

1 回答 1

0
Try this and add required references.  (using System.Web.Helpers;)  

[HttpPost]

    public ActionResult Feedback(FeedbackModel model)
    {
    if (ModelState.IsValid)
    {
    if (this.db.InsertFeedback(model))
    {
     WebMail.SmtpServer = "smtp.gmail.com";
    WebMail.SmtpPort = 587;
    WebMail.EnableSsl = true;
    WebMail.UserName = "youremailID@gmail.com";
    WebMail.Password = "yourpassword";
    WebMail.From = "from@gmail.com";
    WebMail.Send("Email Address", "Mail Subject", "Mail Body");
return RedirectToAction("FeedbackSuccessful");
    }
    else
    {
    ModelState.AddModelError("", "Error! We were unable to process your feedback at this time. Please try again later.");
    }
    }
    return View(model);
    }
于 2013-03-26T12:01:53.383 回答