Пример #1
0
        public static MailMessage GetContactEmail(ContactMailModel model )
        {
            var templatePath = HttpContext.Current.Server.MapPath("~/Views/EmailTemplates/Contact.cshtml");

            var body = EmailTemplateResolver.GetEmailBody(
                templatePath,
                model);

            return new MailMessage(
                    StaticConfig.MailSenderAddress,
                    "*****@*****.**",
                    "Conatct From DIYFE",
                    body);
        }
Пример #2
0
        public ActionResult SendContactEmail(ContactMailModel model)
        {
            var data = new object();

            try
            {
                var email = EmailMessageFactory.GetContactEmail(model);
                var result = EmailClient.SendEmail(email);

                if (!String.IsNullOrEmpty(model.NewsLetter))
                {
                    try
                    {
                        NewsLetter letter = new NewsLetter()
                        {
                            Email = model.Email,
                            DateCreated = DateTime.Now
                        };
                        using (var db = new DIYFE.EF.DIYFEEntities())
                        {
                            db.NewsLetters.Add(letter);
                            db.SaveChanges();
                        }

                    }
                    catch (Exception ex)
                    {
                        data = new { success = false, message = "Message Was Sent...but failed to join news letter." };
                        return Json(data);
                    }
                }
            }
            catch (Exception ex)
            {
                data = new { success = false, message = "Failed to send comment.  Please trying contacting us directly." };
                return Json(data);
            }

            data = new { success = true };

            return Json(data);
        }