public JsonResult sendMessage(QuickContactModel Data) // Send Email to Site Owner { QuickContactModel getMessage = new QuickContactModel() { Name = Data.Name, Email = Data.Email, Subject = Data.Subject, Message = Data.Message, lang = Data.lang }; MailMessage getMail = new MailMessage(); getMail.To.Add("*****@*****.**"); getMail.From = new MailAddress("*****@*****.**"); getMail.Subject = getMessage.Subject; getMail.Body = getMessage.Message + Environment.NewLine + '\n' + "_____________________" + '\n' + getMessage.Name + " (" + getMessage.Email + ")"; getMail.IsBodyHtml = false; SmtpClient setup = new SmtpClient(); setup.Host = "smtp.gmail.com"; setup.Port = 587; setup.EnableSsl = true; NetworkCredential NetworkCre = new NetworkCredential("username", "1234567890"); setup.UseDefaultCredentials = true; setup.Credentials = NetworkCre; QuickContactModel responseStat; try { setup.Send(getMail); } catch (Exception exc) { Response.Write("Send failure: " + exc.ToString()); responseStat = Response_stat("error"); } finally { responseStat = Response_stat("success"); autoReply(getMessage.Email, getMessage.lang); } return(Json(responseStat, JsonRequestBehavior.AllowGet)); }
private QuickContactModel Response_stat(string actionCase) // Response error code to front end with JSON { QuickContactModel respone; respone = new QuickContactModel(); switch (actionCase) { case "success": { respone.errorcode = 0; break; } case "error": { respone.errorcode = 1; break; } } return(respone); }