외부 전자 메일 주소에 대한 사용자 지정 경고를 어떻게 만들 수 있습니까?
-
10-12-2019 - |
문제
우리 회사에서는 SharePoint에 저장된 기밀 정보가 있습니다.일부 정치적으로 효과적인 사람들은 외부 전자 메일 주소로 경고가 전송되도록 추진하고 있습니다.내부 전자 메일 주소가없는 내부 전자 메일 및 경고에 대한 내부 전자 메일 경고를 내부 전자 메일 및 경고로 어떻게 보낼 수 있습니까?
해결책
새 경고 템플릿 만들기
1 꺼내기 템플릿의 복사본을 만들고 이름을 변경하고 사용자 정의 핸들러에 호출을 각각 하나씩 추가합니다.
-
사용자 지정 템플릿을 이름이 끝나면 "ext"를 "ext"합니다.
-
사용자 지정 기능은 사용자 정의 NotificationHandlerAssembly 에 호출합니다.
using System; using System.Runtime.InteropServices; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using System.Xml; namespace Prov.Shared.CCPersonalEmail.Features.AlertTemplates { public class AlertTemplatesEventReceiver : SPFeatureReceiver { public override void FeatureActivated(SPFeatureReceiverProperties properties) { //The Properties we will add to the Alert Template //(Since this feature lives in the same project with the //IAlertNotifyHandler we just refer to our own assembly) string ClassToAdd = "CCPersonalClass"; SPFeatureDefinition FeatDef = (SPFeatureDefinition)properties.Feature.Definition; string ourAssemblyName = FeatDef.ReceiverAssembly; SPWebApplication WebApplication = (SPWebApplication)properties.Feature.Parent; SPWebService WebService = WebApplication.WebService; SPAlertTemplateCollection colSPAT = new SPAlertTemplateCollection(WebService); foreach (SPAlertTemplate SPAT in colSPAT) { if (SPAT.Name.Contains(".Ext")) { SPAT.Delete(); } } foreach (SPAlertTemplate SPAT in colSPAT) { if (SPAT.Name.Contains("SPAlertTemplateType")) { SPAlertTemplate newSPAT = new SPAlertTemplate(); XmlDocument xmlSpit = new XmlDocument(); xmlSpit.LoadXml(SPAT.Xml.ToString()); //create node and add value XmlNode node = xmlSpit.CreateNode(XmlNodeType.Element, "Properties", string.Empty); //create 3 nodes XmlNode nodeAssembly = xmlSpit.CreateElement("NotificationHandlerAssembly"); XmlNode nodeClassName = xmlSpit.CreateElement("NotificationHandlerClassName"); XmlNode nodeProperties = xmlSpit.CreateElement("NotificationHandlerProperties"); nodeAssembly.InnerText = ourAssemblyName; nodeClassName.InnerText = ourAssemblyName.Substring(0,ourAssemblyName.IndexOf(",")) + "." + ClassToAdd; //add to parent node node.AppendChild(nodeAssembly); node.AppendChild(nodeClassName); node.AppendChild(nodeProperties); //add to elements collection xmlSpit.DocumentElement.AppendChild(node); newSPAT.Xml = xmlSpit.InnerXml; newSPAT.Name = SPAT.Name.ToString() + ".Ext"; newSPAT.Id = Guid.NewGuid(); colSPAT.Add(newSPAT); } } foreach (SPTimerServiceInstance timerservice in WebApplication.Farm.TimerService.Instances) { timerservice.Stop(); timerservice.Start(); } } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPWebApplication WebApplication = (SPWebApplication)properties.Feature.Parent; SPWebService WebService = WebApplication.WebService; SPAlertTemplateCollection colSPAT = new SPAlertTemplateCollection(WebService); foreach (SPAlertTemplate SPAT in colSPAT) { if (SPAT.Name.Contains(".Ext")) { SPAT.Delete(); } } } } }
사용자 정의 알림 핸들러 어셈블리
1 클래스 CCPersonalClass는 정의 된 메소드 onnotification 을 포함하는 IAlertNotifyHandler 인터페이스를 구현합니다.
-
사용자 정의 경고를 보내려고 시도합니다 (실패한 경우 정상적인 경고를 보내는 경우)
-
사용자 정의 경고 :
-
사용자 정보 목록에서 ComicoSemail 필드 데이터를 가져옵니다
-
개인 이메일이 비어있는 경우 정상적인 경고 를 보냅니다.
-
개인 이메일이 채워지면
-
내부 이메일로 보통 이메일 보내기
-
외부 주소로 전자 메일을 전송
-
http://
를http://ext-
로 대체 -
외부 전자 메일을 보내면 모든 세부 레코드를 제거하고 머리글을 남겨 둡니다.
{
.using System; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; using System.Text.RegularExpressions; using Framework.Logger; using System.Collections.Specialized; namespace Shared.CCPersonalEmail { class CCPersonalClass: IAlertNotifyHandler { public bool OnNotification(SPAlertHandlerParams alertHandler) { using (new SPMonitoredScope("Shared.CCPersonalClass OnNotification")) { string siteUrl = alertHandler.siteUrl; using (SPSite site = new SPSite(siteUrl + alertHandler.webUrl)) { using (SPWeb web = site.OpenWeb()) { try { return CustomAlertNotification(web, alertHandler, siteUrl); } catch { //if it fails due to configuration still the default alert should work SPUtility.SendEmail(web, alertHandler.headers, alertHandler.body); return false; } } } } } private bool CustomAlertNotification(SPWeb web, SPAlertHandlerParams alertHandler, string siteUrl) { using (new SPMonitoredScope("Shared.CCPersonalClass CustomAlertNotification")) { string PersonalEmail = string.Empty; int eventCount = alertHandler.eventData.GetLength(0); //Get the Personal Email from the User Information List try { PersonalEmail = GetPersonalEmail(alertHandler.headers["to"], web); } catch (Exception e) { Logger.LogError(e, "CCPersonalClass"); } //Send each alert in the alertHandler for (int i = 0; i < eventCount; i++) { try { if (string.IsNullOrEmpty(PersonalEmail)) { SPUtility.SendEmail(web, alertHandler.headers, alertHandler.body); } else { //Send a normal notification to the work email SPUtility.SendEmail(web, alertHandler.headers, alertHandler.body); //Send an abbreviated email to the external email string txt = alertHandler.body.ToString().Replace("http://", "http://ext-"); //Digest messages- removing detail records string strRegex = "<tr>\\s*<td class=\"[a-z]*?\"> <div class=\"nobr\">.*?</td>{0}s*</tr>|"; //Immediate messages- removing detail records strRegex = strRegex + "<tr>\\s*<td class=\"formlabel\">.*<td class=\"altvb\"> </td>\\s*</tr>"; txt = Regex.Replace(txt, strRegex, string.Empty, RegexOptions.Singleline); StringDictionary PersonalHeader = alertHandler.headers; PersonalHeader["cc"] = PersonalEmail; SPUtility.SendEmail(web, PersonalHeader, txt); } } catch (Exception e) { Logger.LogError(e, "CCPersonalClass"); } } if (eventCount > 1) return true; else return false; } } private string GetPersonalEmail(string WorkEmail, SPWeb web) { using (new SPMonitoredScope("Shared.CCPersonalClass GetPersonalEmail")) { SPQuery SelectUser = new SPQuery(); string SelectUserQS = string.Format("<Query><Where><Eq><FieldRef Name='EMail' /><Value Type='Text'>{0}</Value></Eq></Where></Query>", WorkEmail); SelectUser.Query = SelectUserQS; SPList UserList = web.Site.RootWeb.Lists["User Information List"]; SPListItemCollection SelectedUserCol = UserList.GetItems(SelectUser); SPListItem SelectedUser = SelectedUserCol[0]; return (string)SelectedUser["PersonalEmail"]; } } } }
외부 템플릿 을 사용하도록 경고를 설정합니다.
1 기존 컨텐츠가 기능 이벤트 수신기로 업데이트됩니다.
-
기존 경고 :
- site.allwebs.alerts가 adpended 와 같은 템플릿 이름으로 뒤집 힙니다.
-
기존 목록 :
- site.allwebs.lists는 extedpart 에 첨부 된 Alerttemplates를 뒤집었다.
{
.using System; using System.Runtime.InteropServices; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Security; using Prov.Framework.Logger; namespace Prov.Shared.CCPersonalEmail.Features.CCAlerts { [Guid("a3889d39-ea91-441e-9039-157c512441e4")] public class CCAlertsEventReceiver : SPFeatureReceiver { // Set AlertTemplates on sites and alerts to custom templates. public override void FeatureActivated(SPFeatureReceiverProperties properties) { using (SPSite site = (SPSite)properties.Feature.Parent) { AlertTemplateSelector objSelectedAlertTemplate = new AlertTemplateSelector(site); //Add PersonalEmail field if it does not exist yet SPFieldCollection UserInfoFields = site.RootWeb.Lists["User Information List"].Fields; try { bool FieldExists = UserInfoFields.ContainsField("PersonalEmail"); if (!FieldExists) { UserInfoFields.Add("PersonalEmail", SPFieldType.Text, false); } } catch (Exception e) { Logger.LogError(e, "CCPersonalClass"); } foreach (SPWeb web in site.AllWebs) { using (web) { web.AllowUnsafeUpdates = true; foreach (SPList List in web.Lists) { try { List.AlertTemplate = objSelectedAlertTemplate.SwapAlertTemplate(List.AlertTemplate.Name, true); List.Update(); } catch (Exception e) { Logger.LogError(e, "CCAlertsEventReceiver"); } } foreach (SPAlert Alert in web.Alerts) { try { Alert.AlertTemplate = objSelectedAlertTemplate.SwapAlertTemplate(Alert.AlertTemplate.Name, true); Alert.Update(); } catch (Exception e) { Logger.LogError(e, "CCAlertsEventReceiver"); } } web.AllowUnsafeUpdates = false; } } } } // Revert AlertsTemplates on sites and alerts back to out of box templates. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { using (SPSite site = (SPSite)properties.Feature.Parent) { AlertTemplateSelector objSelectedAlertTemplate = new AlertTemplateSelector(site); foreach (SPWeb web in site.AllWebs) { using (web) { web.AllowUnsafeUpdates = true; foreach (SPList List in web.Lists) { try { List.AlertTemplate = objSelectedAlertTemplate.SwapAlertTemplate(List.AlertTemplate.Name, false); List.Update(); } catch (Exception e) { Logger.LogError(e, "CCAlertsEventReceiver"); } } foreach (SPAlert Alert in web.Alerts) { try { Alert.AlertTemplate = objSelectedAlertTemplate.SwapAlertTemplate(Alert.AlertTemplate.Name, false); Alert.Update(); } catch (Exception e) { Logger.LogError(e, "CCAlertsEventReceiver"); } } web.AllowUnsafeUpdates = false; } } } } } }
피쳐 활성화, 비활성화 및 onListCreation 이벤트 핸들러 에 의해 다음 코드가 사용됩니다.
{
.using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint; namespace Shared.CCPersonalEmail { class AlertTemplateSelector { private SPAlertTemplateCollection atc; private SPSite site; public AlertTemplateSelector(SPSite site) { this.site = site; this.atc = new SPAlertTemplateCollection((SPWebService)site.WebApplication.Parent); } public SPAlertTemplate SwapAlertTemplate(string PreviousAlert, bool isActivating) { if ((!PreviousAlert.EndsWith(".Ext")) && (isActivating)) { PreviousAlert = string.Format("{0}.Ext", PreviousAlert); } if ((PreviousAlert.EndsWith(".Ext")) && (!isActivating)) { PreviousAlert = PreviousAlert.Replace(".Ext", ""); } SPAlertTemplate newTemplate = atc[PreviousAlert]; if (newTemplate == null) { if (isActivating) { newTemplate = atc["SPAlertTemplateType.GenericList.Ext"]; } else { newTemplate = atc["SPAlertTemplateType.GenericList"]; } } return newTemplate; } } }
2 미래의 웹 및 그 미래 목록
- SPLISTEventReceiver Liver Liver Liver ListAdded () 이벤트는 사이트 모음에서 생성 된 모든 목록에서 템플릿을 뒤집습니다
{
.namespace Shared.CCPersonalEmail.OnListCreation { public class OnListCreation : SPListEventReceiver { public override void ListAdded(SPListEventProperties properties) { base.ListAdded(properties); SPWeb web = properties.Web; SPList List = web.Lists[properties.ListId]; AlertTemplateSelector objSelectedAlertTemplate = new AlertTemplateSelector(web.Site); List.AlertTemplate = objSelectedAlertTemplate.SwapAlertTemplate(List.AlertTemplate.Name, true); List.Update(); } } }
가사 기능 활성화 중
1
-
rootweb의 사용자 정보 목록에 ComicoSemail 필드 생성
-
코드는 위의 기능 활성화 된 이벤트 수신기에 포함됩니다.
2 피쳐 비활성화 중
- CONTEREMAIL이 내용이되어 비활성화시 제거되지 않으므로
-
- SPLISTEventReceiver Liver Liver Liver ListAdded () 이벤트는 사이트 모음에서 생성 된 모든 목록에서 템플릿을 뒤집습니다
- site.allwebs.lists는 extedpart 에 첨부 된 Alerttemplates를 뒤집었다.
-
-
-
-
다른 팁
단일 목록 만 해당 된 경우 대신 워크 플로를 사용할 수 있습니다.전자 메일을 이메일로 표시 할 일과 세미콜론 구분 된 전자 메일 주소 목록을 추적하기 위해 지주 목록을 만들 수 있습니다.항목이 생성되거나 편집 될 때 (경고 논리가 있어야 하는가) 이메일 주소의 적절한 목록을 조회하고 소수 된 이메일을 그룹화하는 이메일을 찾습니다.