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 に答える