public string Index(ContactMesssage msg) { HttpContext.Response.AddHeader("Content-Type", "application/json; charset=utf-8"); dynamic result = SendContactMessage(msg); JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(result)); }
private dynamic SendContactMessage(ContactMesssage msg) { // Command line argument must the the SMTP host. SmtpClient client = new SmtpClient { Port = 26, Host = "mail.jasonallen.dev", EnableSsl = false, Timeout = 10000, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential("*****@*****.**", "KdF7[4?70k+T") }; MailMessage mm = new MailMessage { From = new MailAddress("*****@*****.**", msg.Name), Sender = new MailAddress("*****@*****.**"), Subject = msg.Subject, SubjectEncoding = Encoding.UTF8, Body = msg.Message, BodyEncoding = Encoding.UTF8, IsBodyHtml = false, DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure }; mm.To.Add("*****@*****.**"); mm.ReplyToList.Add(new MailAddress(msg.Email, msg.Name)); mm.Headers.Add("Disposition-Notification-To", "*****@*****.**"); try { client.Send(mm); } catch (Exception e) { return(new { success = false, error = e.Message }); } finally { mm.Dispose(); client.Dispose(); } return(new { success = true, error = (string)null }); }