public UserController() { _mappingEngine = ObjectFactory.GetInstance<IMappingEngine>(); _jsonPackager = new JsonPackager(); _user = new User(); _email = new Email(); }
public void Delete(Email email) { _context.Email.Remove(email); }
public Email Add(Email email) { return _context.Email.Add(email); }
/// <summary> /// Send a single email /// </summary> /// <param name="email"></param> public void SendMail(Email email) { SendMail(new List<Email> { email }); }
public void SendMail(Email email, Settings settings) { SendMail(new List<Email> { email }, settings); }
public static void SendEmail(string subject, string msg, string sender, string to, bool overrideInterval) { try { if ((DateTime.Now.Subtract(lastemail).Ticks > acceptableInterval || overrideInterval)) { var kfdEmail = new Email(smtpserver); kfdEmail.SetEmail(subject.ToString(), msg.ToString()); kfdEmail.AddToAddress(to); kfdEmail.SetSender(sender); kfdEmail.SetBodyIsHTML(false); kfdEmail.SetTimeoutInSeconds(30); kfdEmail.SendEmail(); lastemail = DateTime.Now; } } catch (Exception e) { var log = new System.Diagnostics.EventLog { Source = e.Source.Trim() }; log.WriteEntry(e.Message); } }
public Report() { _user = new User(); _email = new Email(); }
public HomeController() { _emailAddress = ObjectFactory.GetInstance<EmailAddress>(); _email = ObjectFactory.GetInstance<Email>(); }
public ActionResult ForgotPassword(ForgotPasswordViewModel forgotPasswordViewModel) { if (!ModelState.IsValid) { return View(forgotPasswordViewModel); } MembershipUser user; using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { user = MembershipService.GetUserByEmail(forgotPasswordViewModel.EmailAddress); // If the email address is not registered then display the 'email sent' confirmation the same as if // the email address was registered. There is no harm in doing this and it avoids exposing registered // email addresses which could be a privacy issue if the forum is of a sensitive nature. */ if (user == null) { return RedirectToAction("PasswordResetSent", "Members"); } try { // If the user is registered then create a security token and a timestamp that will allow a change of password MembershipService.UpdatePasswordResetToken(user); unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ModelState.AddModelError("", LocalizationService.GetResourceString("Members.ResetPassword.Error")); return View(forgotPasswordViewModel); } } // At this point the email address is registered and a security token has been created // so send an email with instructions on how to change the password using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var settings = SettingsService.GetSettings(); var url = new Uri(string.Concat(settings.ForumUrl.TrimEnd('/'), Url.Action("ResetPassword", "Members", new { user.Id, token = user.PasswordResetToken }))); var sb = new StringBuilder(); sb.AppendFormat("<p>{0}</p>", string.Format(LocalizationService.GetResourceString("Members.ResetPassword.EmailText"), settings.ForumName)); sb.AppendFormat("<p><a href=\"{0}\">{0}</a></p>", url); var email = new Email { EmailTo = user.Email, NameTo = user.UserName, Subject = LocalizationService.GetResourceString("Members.ForgotPassword.Subject") }; email.Body = _emailService.EmailTemplate(email.NameTo, sb.ToString()); _emailService.SendMail(email); try { unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ModelState.AddModelError("", LocalizationService.GetResourceString("Members.ResetPassword.Error")); return View(forgotPasswordViewModel); } } return RedirectToAction("PasswordResetSent", "Members"); }
private void SendEmailConfirmationEmail(MembershipUser userToSave) { var settings = SettingsService.GetSettings(); var manuallyAuthoriseMembers = settings.ManuallyAuthoriseNewMembers; var memberEmailAuthorisationNeeded = settings.NewMemberEmailConfirmation == true; if (manuallyAuthoriseMembers == false && memberEmailAuthorisationNeeded) { if (!string.IsNullOrEmpty(userToSave.Email)) { // SEND AUTHORISATION EMAIL var sb = new StringBuilder(); var confirmationLink = string.Concat(StringUtils.ReturnCurrentDomain(), Url.Action("EmailConfirmation", new { id = userToSave.Id })); sb.AppendFormat("<p>{0}</p>", string.Format(LocalizationService.GetResourceString("Members.MemberEmailAuthorisation.EmailBody"), settings.ForumName, string.Format("<p><a href=\"{0}\">{0}</a></p>", confirmationLink))); var email = new Email { EmailTo = userToSave.Email, NameTo = userToSave.UserName, Subject = LocalizationService.GetResourceString("Members.MemberEmailAuthorisation.Subject") }; email.Body = _emailService.EmailTemplate(email.NameTo, sb.ToString()); _emailService.SendMail(email); // ADD COOKIE // We add a cookie for 7 days, which will display the resend email confirmation button // This cookie is removed when they click the confirmation link var myCookie = new HttpCookie(AppConstants.MemberEmailConfirmationCookieName) { Value = $"{userToSave.Email}#{userToSave.UserName}", Expires = DateTime.UtcNow.AddDays(7) }; // Add the cookie. Response.Cookies.Add(myCookie); } } }
public ActionResult Create(Guid to) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var viewModel = new CreatePrivateMessageViewModel { To = to }; try { var permissions = RoleService.GetPermissions(null, UsersRole); var settings = SettingsService.GetSettings(); // Check if private messages are enabled if (!settings.EnablePrivateMessages || LoggedOnReadOnlyUser.DisablePrivateMessages == true) { return Content(LocalizationService.GetResourceString("Errors.GenericMessage")); } // Check outbox size of logged in user var senderCount = _privateMessageService.GetAllSentByUser(LoggedOnReadOnlyUser.Id).Count; if (senderCount > settings.MaxPrivateMessagesPerMember) { return Content(LocalizationService.GetResourceString("PM.SentItemsOverCapcity")); } if (senderCount > (settings.MaxPrivateMessagesPerMember - SiteConstants.Instance.PrivateMessageWarningAmountLessThanAllowedSize)) { // Send user a warning they are about to exceed var sb = new StringBuilder(); sb.Append($"<p>{LocalizationService.GetResourceString("PM.AboutToExceedInboxSizeBody")}</p>"); var email = new Email { EmailTo = LoggedOnReadOnlyUser.Email, NameTo = LoggedOnReadOnlyUser.UserName, Subject = LocalizationService.GetResourceString("PM.AboutToExceedInboxSizeSubject") }; email.Body = _emailService.EmailTemplate(email.NameTo, sb.ToString()); _emailService.SendMail(email); } // Set editor permissions ViewBag.ImageUploadType = permissions[SiteConstants.Instance.PermissionInsertEditorImages].IsTicked ? "forumimageinsert" : "image"; unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); } return PartialView(viewModel); } }
public ActionResult Create(CreatePrivateMessageViewModel createPrivateMessageViewModel) { var settings = SettingsService.GetSettings(); if (!settings.EnablePrivateMessages || LoggedOnReadOnlyUser.DisablePrivateMessages == true) { throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { if (ModelState.IsValid) { var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id); var memberTo = MembershipService.GetUser(createPrivateMessageViewModel.To); // Check the user they are trying to message hasn't blocked them if (loggedOnUser.BlockedByOtherUsers.Any(x => x.Blocker.Id == memberTo.Id)) { return Content(PmAjaxError(LocalizationService.GetResourceString("PM.BlockedMessage"))); } // Check flood control var lastMessage = _privateMessageService.GetLastSentPrivateMessage(LoggedOnReadOnlyUser.Id); // If this message they are sending now, is to the same person then ignore flood control if (lastMessage != null && createPrivateMessageViewModel.To != lastMessage.UserTo.Id) { if (DateUtils.TimeDifferenceInSeconds(DateTime.UtcNow, lastMessage.DateSent) < settings.PrivateMessageFloodControl) { return Content(PmAjaxError(LocalizationService.GetResourceString("PM.SendingToQuickly"))); } } // first check they are not trying to message themself! if (memberTo != null) { // Map the view model to message var privateMessage = new PrivateMessage { UserFrom = loggedOnUser, Message = createPrivateMessageViewModel.Message, }; // Check settings if (settings.EnableEmoticons == true) { privateMessage.Message = _configService.Emotify(privateMessage.Message); } // check the member if (!String.Equals(memberTo.UserName, LoggedOnReadOnlyUser.UserName, StringComparison.CurrentCultureIgnoreCase)) { // Check in box size for both var receiverCount = _privateMessageService.GetAllReceivedByUser(memberTo.Id).Count; if (receiverCount > settings.MaxPrivateMessagesPerMember) { return Content(string.Format(LocalizationService.GetResourceString("PM.ReceivedItemsOverCapcity"), memberTo.UserName)); } // If the receiver is about to go over the allowance them let then know too if (receiverCount > (settings.MaxPrivateMessagesPerMember - SiteConstants.Instance.PrivateMessageWarningAmountLessThanAllowedSize)) { // Send user a warning they are about to exceed var sb = new StringBuilder(); sb.Append($"<p>{LocalizationService.GetResourceString("PM.AboutToExceedInboxSizeBody")}</p>"); var email = new Email { EmailTo = memberTo.Email, NameTo = memberTo.UserName, Subject = LocalizationService.GetResourceString("PM.AboutToExceedInboxSizeSubject") }; email.Body = _emailService.EmailTemplate(email.NameTo, sb.ToString()); _emailService.SendMail(email); } // Good to go send the message! privateMessage.UserTo = memberTo; _privateMessageService.Add(privateMessage); try { // Finally send an email to the user so they know they have a new private message // As long as they have not had notifications disabled if (memberTo.DisableEmailNotifications != true) { var email = new Email { EmailTo = memberTo.Email, Subject = LocalizationService.GetResourceString("PM.NewPrivateMessageSubject"), NameTo = memberTo.UserName }; var sb = new StringBuilder(); sb.Append($"<p>{string.Format(LocalizationService.GetResourceString("PM.NewPrivateMessageBody"), LoggedOnReadOnlyUser.UserName)}</p>"); sb.Append(AppHelpers.ConvertPostContent(createPrivateMessageViewModel.Message)); email.Body = _emailService.EmailTemplate(email.NameTo, sb.ToString()); _emailService.SendMail(email); } unitOfWork.Commit(); return PartialView("_PrivateMessage", privateMessage); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); return Content(PmAjaxError(LocalizationService.GetResourceString("Errors.GenericMessage"))); } } else { return Content(PmAjaxError(LocalizationService.GetResourceString("PM.TalkToSelf"))); } } else { // Error send back to user return Content(PmAjaxError(LocalizationService.GetResourceString("PM.UnableFindMember"))); } } return Content(PmAjaxError(LocalizationService.GetResourceString("Errors.GenericMessage"))); } }