Karthik Ramachandran

Karthik Ramachandran

  • 2k
  • 116
  • 25.1k

MVC web application

Aug 5 2018 11:35 AM
[HttpPost]
public ActionResult Contact_us(MailModel mm)
{
//return View();
// validate captcha
if (Session["Captcha"] == null || Session["Captcha"].ToString() != mm.Captcha)
{
ModelState.AddModelError("Captcha", "Wrong value of sum, please try again.");
//dispay error and generate a new captcha
return View();
}
else
{
if (ModelState.IsValid)
{
SmtpClient objSMTP = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"].ToString());
objSMTP.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["MailUserName"].ToString(), ConfigurationManager.AppSettings["MailPassword"].ToString());
System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage();
try
{
objMailMessage.From = new MailAddress(ConfigurationManager.AppSettings["MailUserName"].ToString());
objMailMessage.Subject = "Enquiry received from the Website.";
objMailMessage.To.Add("info@visionsoftwares.com");
objMailMessage.Body = "<b> Name </b> : " + mm.Name + " " + mm.LastName + " <br/><br/> <b> Telephone No : </b>" + mm.Telephone + "<br/><br/><b>Email : </b>" + mm.Email + " <b>Enquiry : </b>" + mm.Message;
objMailMessage.Priority = System.Net.Mail.MailPriority.High;
objMailMessage.IsBodyHtml = true;
objSMTP.Send(objMailMessage);
//Response.Redirect("thankyou.aspx");
}
catch (Exception)
{
throw;
//MessageBox.Show("Message not sent : " + exp.Message);
}
return RedirectToAction("Thankyou");
}
return RedirectToAction("Thankyou");
}
}

Answers (2)