using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Net.Mail; using System.Net; using System.Web.Mvc; using System.Web.Helpers; using System.Threading.Tasks; namespace MailSender.Controllers { public class HomeController : Controller { [HttpGet] public ActionResult Index() { return View(new Models.MailModel()); } [HttpGet] public ActionResult Error(string errMsg) { ViewData.Add("errMsg", errMsg); return View(); } [HttpPost] public ActionResult Index(MailSender.Models.MailModel model) { if (ModelState.IsValid) { var smtpClient = new SmtpClient(Settings.smtpServer, Settings.smtpPort) { Credentials = new NetworkCredential(Settings.user, Settings.pass), EnableSsl = true }; smtpClient.Send(Settings.user, model.EMailTo, model.Subject, model.Content); return RedirectToAction("Index"); } else return RedirectToAction("Error", new { errMsg = "Error nie umiesz pisac maila menelu" }); } } }