public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e) { if (e == null) { return; } if (e.SiteUser == null) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if ( (!siteSettings.RequireApprovalBeforeLogin) && (siteSettings.EmailAdressesForUserApprovalNotification.Length == 0) ) { return; } log.Debug("NotifyAdminUserRegisteredHandler called for new user " + e.SiteUser.Email); if (HttpContext.Current == null) { return; } CultureInfo defaultCulture = SiteUtils.GetDefaultUICulture(); string subjectTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "NotifyAdminofNewUserRegistationSubject.config"); string textBodyTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "NotifyAdminofNewUserRegistationMessage.config"); string siteRoot = SiteUtils.GetNavigationSiteRoot(); SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings(); //lookup admin users and send notification email with link to manage user List <string> adminEmails; if (siteSettings.EmailAdressesForUserApprovalNotification.Length > 0) { adminEmails = siteSettings.EmailAdressesForUserApprovalNotification.SplitOnChar(','); } else { adminEmails = SiteUser.GetEmailAddresses(siteSettings.SiteId, "Admins;"); } //foreach (DataRow row in admins.Rows) foreach (string email in adminEmails) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } //EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); //messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; //messageTask.EmailFromAlias = siteSettings.DefaultFromEmailAlias; //messageTask.EmailTo = email; //messageTask.Subject = string.Format(defaultCulture, subjectTemplate, e.SiteUser.Email, siteRoot); string manageUserLink = siteRoot + "/Admin/ManageUsers.aspx?userid=" + e.SiteUser.UserId.ToInvariantString(); //messageTask.TextBody = string.Format(defaultCulture, textBodyTemplate, siteSettings.SiteName, siteRoot, manageUserLink); //messageTask.SiteGuid = siteSettings.SiteGuid; //messageTask.QueueTask(); Email.Send( smtpSettings, siteSettings.DefaultEmailFromAddress, siteSettings.DefaultFromEmailAlias, string.Empty, email, string.Empty, string.Empty, string.Format(defaultCulture, subjectTemplate, e.SiteUser.Email, siteRoot), string.Format(defaultCulture, textBodyTemplate, siteSettings.SiteName, siteRoot, manageUserLink), false, Email.PriorityNormal); } //WebTaskManager.StartOrResumeTasks(); }
public static void SendApprovalRequestNotification( SmtpSettings smtpSettings, SiteSettings siteSettings, int workflowId, SiteUser submittingUser, News draftNews ) { if (!draftNews.StateId.HasValue) { return; } WorkflowState workflowState = WorkflowHelper.GetWorkflowState(workflowId, draftNews.StateId.Value); if (workflowState == null || workflowState.StateId == -1) { return; } if (workflowState.ReviewRoles.Length == 0 || workflowState.NotifyTemplate.Length == 0) //"ApprovalRequestNotification" { return; } string approvalRoles = workflowState.ReviewRoles; gbSiteMapNode gbNode = SiteUtils.GetSiteMapNodeByZoneId(draftNews.ZoneID); if (gbNode != null) { List <string> authorizedRoles = gbNode.AuthorizedRoles.SplitOnCharAndTrim(';'); List <string> reviewRoles = workflowState.ReviewRoles.SplitOnCharAndTrim(';'); if (authorizedRoles.Count > 0 && reviewRoles.Count > 0) { approvalRoles = string.Empty; foreach (string reviewRole in reviewRoles) { foreach (string role in authorizedRoles) { if (reviewRole.ToLower() == role.ToLower()) { approvalRoles += reviewRole + ";"; } } } } } List <string> emailAddresses = SiteUser.GetEmailAddresses(siteSettings.SiteId, approvalRoles); int queuedMessageCount = 0; EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, workflowState.NotifyTemplate); string subject = template.Subject.Replace("{SiteName}", siteSettings.SiteName); string messageTemplate = template.HtmlBody; List <string> emailTo = (template.ToAddresses.Length > 0 ? ";" + template.ToAddresses : "").SplitOnCharAndTrim(';'); string emailToAddress = string.Empty; foreach (string email in emailAddresses) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } if (!Email.IsValidEmailAddressSyntax(email)) { continue; } if (!emailToAddress.Contains(email + ";")) { emailToAddress += email + ";"; } } foreach (string email in emailTo) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } if (!Email.IsValidEmailAddressSyntax(email)) { continue; } if (!emailToAddress.Contains(email + ";")) { emailToAddress += email + ";"; } } string replyEmail = submittingUser.Email; if (template.ReplyToAddress.Length > 0) { replyEmail += ";" + template.ReplyToAddress; } string fromEmailAlias = (template.FromName.Length > 0 ? template.FromName : siteSettings.DefaultFromEmailAlias); StringBuilder message = new StringBuilder(); message.Append(messageTemplate); message.Replace("{Title}", draftNews.Title); message.Replace("{SubmittedDate}", DateTimeHelper.GetLocalTimeString(draftNews.ApprovedUtc, SiteUtils.GetUserTimeZone(), SiteUtils.GetUserTimeOffset())); message.Replace("{SubmittedBy}", submittingUser.Name); message.Replace("{ContentUrl}", NewsHelper.FormatNewsUrl(draftNews.Url, draftNews.NewsID, draftNews.ZoneID)); EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; messageTask.EmailFromAlias = fromEmailAlias; messageTask.EmailReplyTo = replyEmail; messageTask.EmailTo = emailToAddress; messageTask.EmailCc = template.CcAddresses; messageTask.EmailBcc = template.BccAddresses; messageTask.UseHtml = true; messageTask.Subject = subject; messageTask.HtmlBody = message.ToString(); messageTask.QueueTask(); queuedMessageCount += 1; //Email.Send( // smtpSettings, // siteSettings.DefaultEmailFromAddress, // siteSettings.DefaultFromEmailAlias, // submittingUser.Email, // email, // string.Empty, // string.Empty, // messageSubject, // message.ToString(), // false, // Email.PriorityNormal); WebTaskManager.StartOrResumeTasks(); }
public static void SendPublishRequestNotification( SmtpSettings smtpSettings, SiteSettings siteSettings, SiteUser submittingUser, SiteUser approvingUser, ContentWorkflow draftWorkflow, string publisherRoles, string contentUrl ) { if (string.IsNullOrEmpty(publisherRoles)) { publisherRoles = "Admins;Content Administrators;Content Publishers;"; } Module module = new Module(draftWorkflow.ModuleGuid); if (module == null) { return; } List <string> emailAddresses = SiteUser.GetEmailAddresses(siteSettings.SiteId, publisherRoles); //int queuedMessageCount = 0; CultureInfo defaultCulture = SiteUtils.GetDefaultUICulture(); string messageTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "PublishRequestNotification.config"); string messageSubject = ResourceHelper.GetMessageTemplate(defaultCulture, "PublishRequestNotificationSubject.config").Replace("{SiteName}", siteSettings.SiteName); foreach (string email in emailAddresses) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } if (!Email.IsValidEmailAddressSyntax(email)) { continue; } StringBuilder message = new StringBuilder(); message.Append(messageTemplate); message.Replace("{ModuleTitle}", draftWorkflow.ModuleTitle); message.Replace("{PublishRequestedDate}", draftWorkflow.RecentActionOn.ToShortDateString()); message.Replace("{SubmittedBy}", submittingUser.Name); message.Replace("{ApprovedBy}", approvingUser.Name); message.Replace("{ContentUrl}", contentUrl); Email.Send( smtpSettings, siteSettings.DefaultEmailFromAddress, siteSettings.DefaultFromEmailAlias, submittingUser.Email, email, string.Empty, string.Empty, messageSubject, message.ToString(), false, Email.PriorityNormal); } }
public static void SendApprovalRequestNotification( SmtpSettings smtpSettings, SiteSettings siteSettings, SiteUser submittingUser, ContentWorkflow draftWorkflow, string approvalRoles, string contentUrl ) { if (string.IsNullOrEmpty(approvalRoles)) { approvalRoles = "Admins;Content Administrators;Content Publishers;"; } List <string> emailAddresses = SiteUser.GetEmailAddresses(siteSettings.SiteId, approvalRoles); //int queuedMessageCount = 0; CultureInfo defaultCulture = SiteUtils.GetDefaultUICulture(); string messageTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "ApprovalRequestNotification.config"); string messageSubject = ResourceHelper.GetMessageTemplate(defaultCulture, "ApprovalRequestNotificationSubject.config").Replace("{SiteName}", siteSettings.SiteName); foreach (string email in emailAddresses) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } if (!Email.IsValidEmailAddressSyntax(email)) { continue; } StringBuilder message = new StringBuilder(); message.Append(messageTemplate); message.Replace("{ModuleTitle}", draftWorkflow.ModuleTitle); message.Replace("{ApprovalRequestedDate}", draftWorkflow.RecentActionOn.ToShortDateString()); message.Replace("{SubmittedBy}", submittingUser.Name); message.Replace("{ContentUrl}", contentUrl); if (!Email.IsValidEmailAddressSyntax(draftWorkflow.RecentActionByUserEmail)) { //invalid address log it log.Error("Failed to send workflow rejection message, invalid recipient email " + draftWorkflow.RecentActionByUserEmail + " message was " + message.ToString()); return; } //EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); //messageTask.SiteGuid = siteSettings.SiteGuid; //messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; //messageTask.EmailReplyTo = submittingUser.Email; //messageTask.EmailTo = email; //messageTask.Subject = messageSubject; //messageTask.TextBody = message.ToString(); //messageTask.QueueTask(); //queuedMessageCount += 1; Email.Send( smtpSettings, siteSettings.DefaultEmailFromAddress, siteSettings.DefaultFromEmailAlias, submittingUser.Email, email, string.Empty, string.Empty, messageSubject, message.ToString(), false, Email.PriorityNormal); } //if (queuedMessageCount > 0) { WebTaskManager.StartOrResumeTasks(); } }
public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e) { //if (sender == null) return; if (e == null) { return; } if (e.SiteUser == null) { return; } if (!WebConfigSettings.NotifyAdminsOnNewUserRegistration) { return; } log.Debug("NotifyAdminUserRegisteredHandler called for new user " + e.SiteUser.Email); if (HttpContext.Current == null) { return; } //lookup admin users and send notification email with link to manage user SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); CultureInfo defaultCulture = ResourceHelper.GetDefaultCulture(); //Role adminRole = Role.GetRoleByName(siteSettings.SiteId, "Admins"); //if (adminRole == null) //{ // // TODO: log it? // return; //} //DataTable admins = SiteUser.GetRoleMembers(adminRole.RoleId); string subjectTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "NotifyAdminofNewUserRegistationSubject.config"); string textBodyTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "NotifyAdminofNewUserRegistationMessage.config"); string siteRoot = SiteUtils.GetNavigationSiteRoot(); SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings(); List <string> adminEmails = SiteUser.GetEmailAddresses(siteSettings.SiteId, "Admins;"); //foreach (DataRow row in admins.Rows) foreach (string email in adminEmails) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; //messageTask.EmailTo = row["Email"].ToString(); messageTask.EmailTo = email; messageTask.Subject = string.Format( defaultCulture, subjectTemplate, e.SiteUser.Email, siteRoot ); string manageUserLink = siteRoot + "/Admin/ManageUsers.aspx?userid=" + e.SiteUser.UserId.ToString(CultureInfo.InvariantCulture); messageTask.TextBody = string.Format( defaultCulture, textBodyTemplate, siteSettings.SiteName, siteRoot, manageUserLink ); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.QueueTask(); } WebTaskManager.StartOrResumeTasks(); }