Ejemplo n.º 1
0
        public async Task <JsonResult> DropMeALine(ContactEmailViewModel viewModel)
        {
            var emailSuccessful = "";

            if (!ModelState.IsValid)
            {
                return new JsonResult {
                           Data = emailSuccessful
                }
            }
            ;
            var message = new MailMessage();
            var body    = PartialHelper.RenderViewToString(ControllerContext, "MainContactEmail", viewModel);

            try
            {
                message.To.Add(new MailAddress(viewModel.RecipientEmail));

                message.Subject    = "Attn Site Admin: " + viewModel.Subject;
                message.Body       = body;
                message.IsBodyHtml = true;
                var emailModel = new ContactEmailViewModel()
                {
                    UserGUID           = viewModel.UserGUID,
                    Content            = body,
                    SenderEmailAddress = viewModel.SenderEmailAddress,
                    SenderName         = viewModel.SenderName,
                    EmailTypeID        = (int)EmailType.EmailTypes.Other,
                    Subject            = "Attn Site Admin: " + viewModel.Subject
                };
                using (var smtp = new SmtpClient())
                {
                    await smtp.SendMailAsync(message);
                }
                landingPageService.EmailSent(emailModel);
                return(new JsonResult {
                    Data = "Success"
                });
            }
            catch (Exception e)
            {
                message.Dispose();
            }
            return(new JsonResult {
                Data = emailSuccessful
            });
        }