/// <summary>
 /// 邮件管理
 /// </summary>
 /// <returns></returns>
 public ActionResult ManageEmails()
 {
     pageResourceManager.InsertTitlePart("邮件管理");
     EmailSettings emailSettings = emailSettingsManager.Get();
     EmailSettingsEditModel emailSettingsEditModel = new EmailSettingsEditModel(emailSettings);
     return View(emailSettingsEditModel);
 }
 public ActionResult ManageEmailOtherSettings()
 {
     EmailSettings emailSettings = emailSettingsManager.Get();
     EmailSettingsEditModel emailSettingsEditModel = new EmailSettingsEditModel(emailSettings);
     return View(emailSettingsEditModel);
 }
        public ActionResult ManageEmailOtherSettings(EmailSettingsEditModel model)
        {
            try
            {
                emailSettingsManager.Save(model.AsEmailSettings());
                return Json(new StatusMessageData(StatusMessageType.Success, "保存成功"));
            }
            catch (Exception e)
            {

            }
            return Json(new StatusMessageData(StatusMessageType.Error, "保存失败"));
        }
        /// <summary>
        /// 保存检测邮箱设置
        /// </summary>
        /// <param name="emailSettingsEditModel"></param>
        /// <returns></returns>
        public ActionResult SaveEmail(EmailSettingsEditModel emailSettingsEditModel)
        {
            //保存邮箱设置
            EmailSettings emailSettings = null;
            try
            {
                emailSettings = emailSettingsEditModel.AsEmailSettings();
                emailSettingsManager.Save(emailSettings);
            }
            catch (Exception)
            {
                return Json(new StatusMessageData(StatusMessageType.Error, "保存失败!"));
            }

            //发送测试邮件
            string errorMessage;
            MailMessage mail = new MailMessage(emailSettingsEditModel.UserEmailAddress, emailSettingsEditModel.UserEmailAddress);
            mail.Subject = "这是一封测试邮件";
            mail.Body = "邮件设置检测成功!";
            mail.IsBodyHtml = false;

            if (!emailService.Send(mail, out errorMessage))
            {
                //如果用户名与邮箱不一样,则将用户名改为与邮箱一样
                if (emailSettings.SmtpSettings.UserEmailAddress != emailSettings.SmtpSettings.UserName)
                    emailSettings.SmtpSettings.UserName = emailSettings.SmtpSettings.UserEmailAddress;
                else
                    emailSettings.SmtpSettings.UserName = emailSettings.SmtpSettings.UserEmailAddress.Split('@')[0];

                emailSettingsManager.Save(emailSettings);
                if (!emailService.Send(mail, out errorMessage))
                {
                    return Json(new StatusMessageData(StatusMessageType.Error, "保存成功,但邮件检测失败,原因是:<br/>" + errorMessage));
                }
            }

            return Json(new StatusMessageData(StatusMessageType.Success, "保存成功!"));
        }