Exemplo n.º 1
0
        public ActionResult Contact(EnquiryModel model)
        {
            if (ModelState.IsValid)
            {
                string body = CreateEmailMessage(model);

                MailMessage mail = new MailMessage();
                mail.To.Add(new MailAddress(WebSettings.AdminEmail));
                mail.Body = body;
                mail.IsBodyHtml = true;

                try
                {
                    using (SmtpClient client = new SmtpClient())
                    {
                      client.Send(mail);
                    }

                    return RedirectToAction("Contact", new { status = true });
                }
                catch (Exception)
                {
                    return RedirectToAction("Contact", new { status = false });

                }

            }
            return View(model);
        }
Exemplo n.º 2
0
 private string CreateEmailMessage(EnquiryModel model)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendLine("<b>CUSTOMER ENQUIRY</b><br />");
     sb.AppendLine(string.Format("Customer Name : \t {0} <br />", model.Name));
     sb.AppendLine(string.Format("Customer Telephone : \t {0} <br />", model.Telephone));
     sb.AppendLine(string.Format("Customer Email : \t {0} <br />", model.Email));
     sb.AppendLine(string.Format("Message : \t {0} <br />", model.Message));
     return sb.ToString();
 }