Translate

Monday, October 8, 2012

List E-mail Events and SPEmailEventReceiver

List E-mail Events and SPEmailEventReceiver

The class SPEmailEventReceiver has only one method " EmailReceived  " which is used trap the event when a list receives an email message.

To implement "EmailReceived" this method we need to create a class by inheriting the SPEmailEventReciever class.


The method "EmailReceived" accepts three parameters  (SPList,SPEmailMessage,String)
1. SPList
The SPList parameter actually represents the list that received the e-mail message which can be any List Type.

2. SPEmailMessage
SPEmailMessage is the actual e-mail that was send to the target list,We can use this parameter to get to the parts of the e-mail message and read the sender information, body of the e-mail, and any attachments ect.

3.String value.


The last parameter which is of String data type which is also called as receiverData , is a string and it contains the event receiver definition data.


sample code


 public class SampleEmailReceivedDemo: SPEmailEventReceiver
    {
        public override void EmailReceived(SPList targetList,SPEmailMessage SpMessage,string receiverData)
        {
            SPListItem listItem = targetList.Items.Add();
            listItem["Subject"] = SpMessage.Headers["Subject"];
            listItem["MessageBody"] = SpMessage.HtmlBody;
            listItemUpdate();
        }
    }






No comments:

Post a Comment