public ActionResult Contact(Models.ContactModels c)
 {
     if (ModelState.IsValid)
     {
         try
         {
             MailMessage   msg  = new MailMessage();
             SmtpClient    smtp = new SmtpClient();
             MailAddress   from = new MailAddress(c.Email.ToString());
             StringBuilder sb   = new StringBuilder();
             msg.To.Add("*****@*****.**");
             msg.Subject    = "Contact Us";
             msg.IsBodyHtml = false;
             smtp.Host      = "mail.yourdomain.com";
             smtp.Port      = 25;
             sb.Append("First name: " + c.FirstName);
             sb.Append(Environment.NewLine);
             sb.Append("Last name: " + c.LastName);
             sb.Append(Environment.NewLine);
             sb.Append("Email: " + c.Email);
             sb.Append(Environment.NewLine);
             sb.Append("Comments: " + c.Comment);
             msg.Body = sb.ToString();
             smtp.Send(msg);
             msg.Dispose();
             return(View("Success"));
         }
         catch (Exception)
         {
             return(View("Error"));
         }
     }
     return(View());
 }
Example #2
0
        public ActionResult Contact(Models.ContactModels contactModels)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress("*****@*****.**");
                    mail.To.Add("*****@*****.**");
                    mail.Subject = "Contact message from " + contactModels.FirstName + contactModels.LastName;
                    mail.Body    = string.Format("{0} at {1} says: {2}", contactModels.FirstName, contactModels.Email, contactModels.Comment);

                    SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
                    smtpServer.Port        = 465;
                    smtpServer.EnableSsl   = true;
                    smtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "temple12");


                    smtpServer.Send(mail);
                    return(View("Success"));
                }
                catch (Exception)
                {
                    return(View("Error"));
                }
            }
            return(View());
        }