SPUtility.SendEmail

First, in a feature receiver, I swapped the Event content type with the Schedule content type to take advantage of the Attendees field (and the cool Free/Busy field!):

SPList list = lists["Calendar"];
SPContentType newContentType =
    list
.ContentTypes.Add(list.ParentWeb.ContentTypes[SPBuiltInContentTypeId.Schedule]);
SPContentType oldContentType = list.ContentTypes[0];
string name = oldContentType.Name;
string description = oldContentType.Description;
oldContentType
.Delete();
newContentType
.Name= name;
newContentType
.Description= description;
newContentType
.Update();

The form now looks like this:

enter image description here

Second, I added an Event Receiver that sends the notices:

publicoverridevoidItemAdded(SPItemEventProperties properties)
{
   
SPList list = properties.List;
   
SPListItem item = properties.ListItem;
 
 
SPFieldUserValueCollection values = item[SPBuiltInFieldId.ParticipantsPicker]asSPFieldUserValueCollection;

   
List<string> emails =newList<string>();
   
foreach(SPFieldUserValue value in values)
   
{
       
SPUser user = value.User;
     
 
if(!string.IsNullOrEmpty(user.Email))
   
   
{
            emails
.Add(user.Email);
       
}
 
 
}

   
if(emails.Count>0)
   
{
     
 
StringDictionary headers =newStringDictionary();
   
    headers
.Add("to",string.Join(";", emails.ToArray()));
     
  headers
.Add("subject", item.Title);
     
 
SPUtility.SendEmail(web, headers, body);
 
 
}
}
posted @ 2012-04-19 09:51  大刀客  阅读(622)  评论(0编辑  收藏  举报