Exemplo n.º 1
0
        public async Task <ActionResult> Contact(ContactUsViewModels contact)
        {
            if (ModelState.IsValid)
            {
                var body    = "<p>Email From: {0} ({1})</p> <p>Message:</p><p>{2}</p>";
                var message = new MailMessage();
                message.To.Add(new MailAddress("*****@*****.**"));
                message.From       = new MailAddress(contact.Email);
                message.Subject    = "Message From Visitor";
                message.Body       = string.Format(body, contact.Name, contact.Email, contact.Message);
                message.IsBodyHtml = true;
                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = "******",
                        Password = "******"
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp.gmail.com";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;
                    await smtp.SendMailAsync(message);

                    return(RedirectToAction("Index"));
                }
            }
            return(View(contact));
        }
Exemplo n.º 2
0
        public ActionResult SendEnquiry(ContactUsViewModels ContactUsViewModels)
        {
            string body = ("Message: " + ContactUsViewModels.Message +
                           "<br/>From:- " +
                           "<br/> Name:" + ContactUsViewModels.Name +
                           "<br/> EmpNo:" + ContactUsViewModels.EmpNo +
                           "<br/> Mobile No:" + ContactUsViewModels.MobileNo +
                           "<br/> Email:" + ContactUsViewModels.Email +
                           "<br/> <br /> Sent by: IRD-SRIC, IIT Roorkee");

            FormServices formServices = new FormServices();

            formServices.SendEmail("*****@*****.**", ContactUsViewModels.Email, ContactUsViewModels.Subject, body);
            ViewBag.Status  = true;
            ViewBag.Message = "Email has been sent successfully. We will contact you soon.";
            ModelState.Clear();
            return(View("Contact", new ContactUsViewModels()));
        }