public ActionResult Index(int?page, int?accountId, string Keyword)
        {
            var templateListVM = new EmailTemplateListVM()
            {
                AccountId = accountId ?? 0,
                PageIndex = page ?? 1,
                PageSize  = SettingsManager.EmailTemplate.PageSize,
                Keyword   = Keyword
            };
            int count;
            var templates = _templateService.GetPagedElements(templateListVM.PageIndex - 1, templateListVM.PageSize, templateListVM.Keyword, templateListVM.AccountId, out count);

            foreach (var item  in templates)
            {
                item.EmailAccount = _accountService.GetById(item.EmailAccountId);
            }
            // var templateDtos = _mapper.Map<IEnumerable<EmailTemplate>, IEnumerable<EmailTemplateVM>>(templates.AsEnumerable());
            // templateListVM.EmailTemplates = templateDtos;

            templateListVM.TotalCount = count;

            var accountList = _accountService.GetElements().OrderByDescending(c => c.Email).ToList();
            var categories  = new SelectList(accountList, "Id", "Email");

            ViewBag.Categories = categories;

            templateListVM.EmailTemplates = new StaticPagedList <EmailTemplate>(templates, templateListVM.PageIndex, templateListVM.PageSize, templateListVM.TotalCount);
            //  ViewBag.OnePageOfEmailTemplates = templatesAsIPagedList;

            ViewBag.PageSizes = new SelectList(Site.PageSizes());

            return(View(templateListVM));
        }
        public JsonResult Reply(EmailIM vm)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            var smtp = _emailAccountServices.GetElements().Where(m => m.IsDefault).FirstOrDefault();

            if (smtp == null)
            {
                AR.SetWarning(Messages.SetDefaultEmailAccount);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
            try
            {
                _emailingService.SendMail(SettingsManager.Site.SiteName, SettingsManager.Site.MailTo, vm.MailTo, string.Empty, vm.Subject, vm.Body,
                                          smtp.Smtpserver, smtp.Email, SettingsManager.Site.SiteName, smtp.UserName, EncryptionHelper.Decrypt(smtp.Password), smtp.Port, smtp.EnableSsl);

                AR.SetSuccess(String.Format(Messages.AlertSendSuccess, EntityNames.Email));
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
            catch (Exception er)
            {
                AR.Setfailure(er.Message);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            //var result =  _emailService.SendMail(SettingsManager.Site.SiteName, vm.MailTo, vm.Subject, vm.Body);
        }