Esempio n. 1
0
        private static void SendEmail(ContactUsModel model)
        {
            //use thread pool to prevent the controller from blocking the SendAsync method
            ThreadPool.QueueUserWorkItem(t =>
            {
                MailMessage mail = new MailMessage();

                SmtpClient SmtpServer = new SmtpClient();

                mail.To.Add("*****@*****.**");
                mail.Subject = "Runner's Tracker User Feedback";
                mail.IsBodyHtml = false;
                mail.Body = "From: " + model.FromName + "\n\n" +model.Comment;

                SmtpServer.SendCompleted += delegate(object sender, AsyncCompletedEventArgs e)
                {
                    if (e.Error != null)
                    {
                        System.Diagnostics.Trace.TraceError(e.Error.ToString());
                        logger.Info(e.Error.ToString());
                    }
                    MailMessage userMessage = e.UserState as MailMessage;
                    if (userMessage != null)
                    {
                        userMessage.Dispose();
                    }
                };
                SmtpServer.SendAsync(mail, mail);
            });
        }
Esempio n. 2
0
 public ActionResult ContactUs(ContactUsModel model)
 {
     if (ModelState.IsValid)
     {
         SendEmail(model);
         return RedirectToAction("ContactUsComplete", "Home");
     }
     else
     {
         return View();
     }
 }