Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
간단한 MOSS 메일 알림 커스터마이징 하는 방법입니다.
아래 KB 내용에 대한 설명입니다.
How to create a custom e-mail alert handler in Microsoft Office SharePoint Server
https://support.microsoft.com/kb/948321/en-us
아래 순서로 진행하시면 됩니다..
1. 커스텀 메일 알림 처리기의 개발
이 처리기는 실제로 알림 메일을 보내는 주체입니다.
아래 샘플 코드를 입력하셔서 클래스를 빌드하시고, GAC 에 등록합니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint;
using System.Web;
namespace MOSSAlert
{
public class CustomMailAlert : IAlertNotifyHandler
{
#region IAlertNotifyHandler Members
public bool OnNotification(SPAlertHandlerParams ahp)
{
SPSite site = null;
SPWeb web = null;
try
{
//System.Diagnostics.Debugger.Break(); // 디버그 붙이려면 주석해제..
site = new SPSite(ahp.siteUrl + ahp.webUrl);
web = site.OpenWeb();
SPList list = web.Lists[ahp.a.ListID];
SPListItem item = list.GetItemById(ahp.eventData[0].itemId);
string FullPath = HttpUtility.UrlPathEncode(ahp.siteUrl + "/" + ahp.webUrl + "/" + list.Title + "/" + item.Name);
string ListPath = HttpUtility.UrlPathEncode(ahp.siteUrl + "/" + ahp.webUrl + "/" + list.Title);
string webPath = HttpUtility.UrlPathEncode(ahp.siteUrl + "/" + ahp.webUrl);
string build = "";
string eventType="";
if (ahp.eventData[0].eventType == 1)
eventType = "Added";
else if (ahp.eventData[0].eventType == 2)
eventType = "Changed";
else if (ahp.eventData[0].eventType == 3)
eventType = "Deleted";
// 이 아래 부분이 실제 알림 메일의 내용 부분입니다.
build =
"<style type=\"text/css\">.style1 { font-size: small; border: 1px solid #000000;" +
"background-color: #DEE7FE;}.style2 { border: 1px solid #000000;}</style></head>" +
"<p><strong>아이템 이름 -> " + item.Name.ToString() + "</strong> has been " + eventType + "</p>" +
"<table style=\"width: 100%\" class=\"style2\"><tr><td style=\"width: 25%\" class=\"style1\">" +
"<a href=" + webPath + "/_layouts/mysubs.aspx>Modify my Settings</a></td>" +
"<td style=\"width: 25%\" class=\"style1\"> <a href=" + FullPath + ">View " + item.Name + "</a></td>" +
"<td style=\"width: 25%\" class=\"style1\"><a href=" + ListPath + ">View " + list.Title + "</a></td>" +
" </tr></table>";
string subject = list.Title.ToString();
SPUtility.SendEmail(web, true, false, ahp.headers["to"].ToString(), subject, build);
return false;
}
catch (System.Exception ex)
{
return false;
}
finally
{
if (web != null)
web.Dispose();
if (site != null)
site.Dispose();
}
}
#endregion
}
}
2. 기본 알림 템플릿의 수정
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Xml 에 있는 기본 알림 템플릿을 수정해야 합니다.
우선 기본 알림 템플릿인 alerttemplates.xml 을 복사해서 CustomAlertTemplates.xml을 만듭니다.

복잡한 XML 내용을 조금 정리해서 표시하면 내용을 보면 대략 아래와 같은 구조입니다.
각 블록들을 보시면 문서 라이브러리나, 커스텀 리스트, 공지사항, 연락처 등등에 각기 다른 알림 메일 형식을 붙일 수 있음을 알 수 있습니다.
여기에서는 공지사항의 알림만을 바꾸어 보도록 하겠습니다.

공지사항 부분(위 그림의 Name = SPAlertTemplateType.Announcements)을 찾아서 프로퍼티 태그를 찾습니다.
<Properties>
<ImmediateNotificationExcludedFields>ID;Author;Editor;Modified_x0020_By;Created_x0020_By;_UIVersionString;ContentType;TaskGroup;IsCurrent;Attachments;NumComments;</ImmediateNotificationExcludedFields>
<DigestNotificationExcludedFields>ID;Author;Editor;Modified_x0020_By;Created_x0020_By;_UIVersionString;ContentType;TaskGroup;IsCurrent;Attachments;NumComments;</DigestNotificationExcludedFields>
프로퍼티 태그의 위 태그 뒤쪽에 아래 부분을 붙입니다. 클래스 이름이나 퍼블릭 키 토큰은 빌드하신 대로 바꾸셔야 합니다.
<NotificationHandlerAssembly>MOSSAlert, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f693eecbef42f40b</NotificationHandlerAssembly>
<NotificationHandlerClassName>MOSSAlert.CustomMailAlert</NotificationHandlerClassName>
<NotificationHandlerProperties></NotificationHandlerProperties>
3. 커스텀 알림 처리기를 등록하기
제작된 알림 처리기를 MOSS 에 등록해주는 과정입니다. STSADM 을 이용합니다.
알림 템플릿의 업데이트 명령입니다. https://mossdev 사이트의 메일 알림 템플릿을 바꾸고 있습니다.
stsadm -o updatealerttemplates -url https://mossdev -filename "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\XML\CustomAlertTemplates.xml"
테스트를 좀 더 원활히 하기 위해 MOSS 타이머 서비스의 설정 변경이 필요합니다. 아래 명령어는 MOSS 서비스가 알림을 보내기 위해 체크하는 시간 간격을 설정합니다. 1분 단위로 바꾸고 있습니다. ( https://technet2.microsoft.com/windowsserver/WSS/en/library/0eb072fe-8321-483b-9d1e-3412e3f42a481033.mspx?mfr=true )
stsadm -o setproperty -pn job-immediate-alerts -pv "every 1 minutes"
iisreset 하고 서비스 관리자를 띄워서 Windows SharePoint Service Timer service 를 재시작 합니다.
4. 테스트
공지사항 리스트에서 메일 알림을 설정하고 (변경 사항 즉시 보내기) 공지사항에 글을 올리면 아래와 같은 메일 알림을 수신할 수 있습니다.

5. 기타
- 위 테스트를 하시려면, 나가는 메일 설정이 되어 있어야 합니다.
- Windows 2008 에서는 POP3 가 없기 때문에, 테스트를 위하여 공짜 SMTP/POP3 서버를 다운로드 하셔서 활용하시기 바랍니다.
Ex : https://www.download.com/ArGoSoft-Mail-Server-Freeware/3000-2165_4-10364910.html
추가 사항 :
알림 설정이 신규 추가되거나 변경되었을 경우의 이벤트를 처리하려면 IAlertUpdateHandler Interface (Microsoft.SharePoint) 를 사용하셔야 합니다.
전체적인 아키텍쳐의 설명은 아래 블로그를 참고하시기 바랍니다.
Customizing Alert Notifications and Alert Templates in Windows SharePoint Services 3.0