public ActionResult Create(EmailAccountModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var emailAccount = new EmailAccount()
                {
                    DisplayName = model.DisplayName,
                    Email = model.Email,
                    EnableSsl = model.EnableSsl,
                    Host = model.Host,
                    Password = model.Password,
                    Port = model.Port,
                    UseDefaultCredentials = model.UseDefaultCredentials,
                    Username = model.Username
                };
                _emailAccountService.InsertEmailAccount(emailAccount);

                return RedirectToAction("List");
            }

            return View(model);
        }
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
                return AccessDeniedView();

            var model = new EmailAccountModel();
            //default values
            model.Port = 25;
            return View(model);
        }
        public ActionResult SendTestEmail(EmailAccountModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
                return AccessDeniedView();

            var emailAccount = _emailAccountService.GetEmailAccountById(model.Id);
            if (emailAccount == null)
                //No email account found with the specified id
                return RedirectToAction("List");

            try
            {
                if (String.IsNullOrWhiteSpace(model.SendTestEmailTo))
                    throw new AaronException("Enter test email address");

                var from = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
                var to = new MailAddress(model.SendTestEmailTo);
                string subject = _webSettings.WebName + ". Kiểm tra tính năng gửi email.";
                string body = "Tính năng gửi Email hoạt động tốt!";
                _emailSender.SendEmail(emailAccount, subject, body, from, to);
            }
            catch
            {

            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Edit(EmailAccountModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
                return AccessDeniedView();

            var emailAccount = _emailAccountService.GetEmailAccountById(model.Id);
            if (emailAccount == null)
                //No email account found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                emailAccount.DisplayName = model.DisplayName;
                emailAccount.Email = model.Email;
                emailAccount.EnableSsl = model.EnableSsl;
                emailAccount.Host = model.Host;
                emailAccount.Password = model.Password;
                emailAccount.Port = model.Port;
                emailAccount.UseDefaultCredentials = model.UseDefaultCredentials;
                emailAccount.Username = model.Username;
                _emailAccountService.UpdateEmailAccount(emailAccount);

                return RedirectToAction("Edit", new { id = emailAccount.Id });
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }