Esempio n. 1
0
 public ActionResult TestEmailSettings(FormCollection collection)
 {
     var msg = new GenericMessage();
     using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
     {
         foreach (var key in collection.AllKeys)
         {
             var settings = SettingsService.Get(key);
             if (settings != null)
             {
                 settings.Value = collection[key];
             }
         }
         try
         {
             unitOfWork.Commit();
             var mail = new Email
             {
                 Subject = string.Format("【{0}】测试邮件", SettingsService.Get()[AppConstants.SiteName].Value),
                 Body = "测试邮件,请勿回复",
                 NameTo = "Hubert",
                 EmailFrom = SettingsService.Get()[AppConstants.NotificationReplyEmail].Value,
                 EmailTo = SettingsService.Get()[AppConstants.NotificationReplyEmail].Value
             };
             _emailService.SendMail(mail);
             msg.Message = "一份测试邮件已经发送到你的通知邮箱中。";
             msg.MessageType = GenericMessageType.success;
             TempData[AppConstants.MessageViewBagName] = msg;
         }
         catch (Exception ex)
         {
             LoggingService.Error(ex);
             msg.Message = "邮件发送失败,请检查你填写的信息是否正确。";
             msg.MessageType = GenericMessageType.warning;
         }
     }
     return RedirectToAction("Email");
 }
Esempio n. 2
0
 public void SendMail(Email email)
 {
     SendMail(new List<Email> { email });
 }
Esempio n. 3
0
        /// <summary>
        /// Create new user
        /// </summary>
        /// <param name="newUser"></param>
        /// <returns></returns>
        public UserStatus CreateUser(User model)
        {
            model = SanitizeUser(model);

            var status = UserStatus.Success;

            if (string.IsNullOrEmpty(model.UserName))
            {
                status = UserStatus.InvalidUserName;
            }
            if (this._userRepository.GetUser(model.UserName) != null)
            {
                status = UserStatus.DuplicateUserName;
            }
            if (this._userRepository.GetUserByEmail(model.Email) != null)
            {
                status = UserStatus.DuplicateEmail;
            }
            if (string.IsNullOrEmpty(model.Password))
            {
                status = UserStatus.InvalidPassword;
            }
            if (status == UserStatus.Success)
            {
                model.Password = GeneratePasswordHash(model.Password);
                var newMemberStartingRole = int.Parse(this._settingsRepository.Get(AppConstants.NewMemberStartingRole).Value);
                model.Role = this._roleRepository.Get(newMemberStartingRole);
                model.Slug = model.UserName;
                try
                {
                    if (this._settingsRepository.Get(AppConstants.EmailAdminOnNewMemberSignUp).Value.Equals("true"))
                    {
                        model.ActivationKey = GeneratePasswordHash(model.UserName).Substring(8, 8);
                        var result = this._userRepository.Add(model);
                        // 发送邮件给管理员,
                        // 发送激活信息给注册用户
                        var email = new Email
                        {
                            Body = _emailService.ActivationTemplate(model.UserName,model.ActivationKey),
                            EmailFrom = _settingsRepository.Get(AppConstants.NotificationReplyEmail).Value,
                            EmailTo = model.Email,
                            NameTo = model.UserName,
                            Subject = string.Format("{0}{1}",_settingsRepository.Get(AppConstants.SiteName).Value, _localizationService.Get("账号激活邮件"))
                        };
                        _emailService.SendMail(email);
                    }
                    else
                    {
                        this._userRepository.Add(model);
                        model.ActivationKey = string.Empty;
                    }
                }catch(Exception)
                {
                    status = UserStatus.UserRejected;
                }
            }
            return UserStatus.Success;
        }