internal static bool SendSupportEmailMessage(string subject, string message) { Logger.Instance.LogFunctionEntry(typeof(EmailHelper).Name, "SendSupportEmailMessage"); var emailMsg = new EmailRequestDto { To = new List<EmailAddressDto> { new EmailAddressDto { Address = EmailConfigSettings.Instance().DefaultSupportEmailAddress } }, Subject = subject, Body = message, IsBodyHtml = false }; var resp = new EmailWorker().SendSystemEmail(emailMsg); if (!resp.IsSuccessful) { if (resp.ValidationMessages.Any()) { Logger.Instance.Error(typeof(EmailHelper).Name, "SendSupportEmailMessage", resp.ValidationMessages); } if (resp.FailureMessages.Any()) { // We can't gracefully handle any of these failure messages so just // log them and throw a business exception to try again later. Logger.Instance.Error(typeof(EmailHelper).Name, "SendSupportEmailMessage", resp.FailureMessages); } Logger.Instance.Error(typeof(EmailHelper).Name, "SendSupportEmailMessage", "Email could not be sent, no validation or failure messages returned."); } Logger.Instance.LogFunctionExit(typeof(EmailHelper).Name, "SendSupportEmailMessage"); return resp.IsSuccessful; }
/// <summary> /// Creates a password reset token and emails a link to the user to change their password. /// </summary> /// <param name="email">Email address of the user.</param> public void SendPasswordReset(string email) { if (String.IsNullOrWhiteSpace(email)) throw new ArgumentOutOfRangeException("email"); var username = Membership.GetUserNameByEmail(email); if (string.IsNullOrEmpty(username)) { throw new BusinessException(AuthBusinessExceptionTypes.Login_UserNameNotFound, "User does not exist in our local DB"); } User user = UserRepository.Value.SingleOrDefault(t => t.Username == username); if (user == null) { throw new BusinessException( AuthBusinessExceptionTypes.Login_UserNameNotFound, "User does not exist in our local DB"); } var token = Guid.NewGuid().ToString(); var resetToken = new ResetUserPasswordToken { ResetTokenDateTime = DateTime.Now, UserId = user.UserId }; DbCacheManager.Add(token, resetToken); var tokenLink = string.Format("{0}{1}?token={2}", EMRMCoreConfigSettings.Instance().AdxUrl, UserConfigSettings.Instance().ForgotPasswordResetAdxRelPath, token); var body = string.Format(UserMessages.Email_ResetPassword_ResetTokenMessage_Body, email, tokenLink); var emailMsg = new EmailRequestDto { To = new List<EmailAddressDto> { new EmailAddressDto { Address = email } }, Subject = UserMessages.Email_ResetPassword_ResetTokenMessage_Subject, Body = body, EmailType = EmailTypes.SystemEmail, IsBodyHtml = false }; var resp = new EmailWorker().SendSystemEmail(emailMsg); if (!resp.IsSuccessful) { if (resp.ValidationMessages.Any()) { // Any user generated validation errors should have been caught // earlier, treat these as system exceptions Logger.Instance.Error(this.GetType().Name, "SendPasswordReset", resp.ValidationMessages); throw new ApplicationException("Unexpected validation errors"); } if (resp.FailureMessages.Any()) { // We can't gracefully handle any of these failure messages so just // log them and throw a business exception to try again later. Logger.Instance.Error(this.GetType().Name, "SendPasswordReset", resp.FailureMessages); throw new BusinessException( AuthBusinessExceptionTypes.Reset_CouldNotSendEmail, "Failure sending message, see FailureMessage collection.", resp.FailureMessages); } Logger.Instance.Error(this.GetType().Name, "SendPasswordReset", "Email could not be sent, no validation or failure messages returned."); throw new ApplicationException("Email could not be sent, no validation or failure messages returned."); } }