Esempio n. 1
0
        public void SendContactRequest(ContactModel request)
        {
            var template = ResourceHelper.GetEmbeddedResource(
                Assembly.GetExecutingAssembly(),
                "Nesjartun.Contact.ContactTemplate.html");

            var content = template
                .Replace("{name}", request.Name)
                .Replace("{phone}", request.Phone)
                .Replace("{email}", request.Email)
                .Replace("{message}", request.Message);

            var mail = new MailMessage(
                "*****@*****.**",
                "*****@*****.**",
                "Kontaktforespørsel fra: " + request.Name,
                content)
            {
                IsBodyHtml = true
            };

            using (var client = new SmtpClient())
            {
                client.Send(mail);
            }
        }
        public ActionResult Submit(ContactModel model)
        {
            if (!ModelState.IsValid) return View("_Form", model);

            try
            {
                _contactService.SendContactRequest(model);
            }
            catch (Exception e)
            {
                //TODO: Log
                return PartialView("_Error");
            }
            return PartialView("_Success");
        }