RiverStorm
RiverStorm

Reputation: 11

Question - Should I use SPItemReceiver or SPEmailEventReceiver

I have custom SharePoint Document Library which I use to upload spreadsheet data into a database. When a spreadsheet is uploaded, the SPItemReceiver triggers, and upload the data. Now, I would like to add an incoming email feature to the document library.

My question is...after the document library has received the spreadsheet by email. Should I use the override-able method EmailReceived of the SPEmailEventReceiver to process the data in the spreadsheet or still use the SPItemReceiver?

I gather I could use either, but I would like to know your opinion which is better and why.

Thanks in advance

Upvotes: 1

Views: 860

Answers (1)

Madhur Ahuja
Madhur Ahuja

Reputation: 22661

You should use SPEmailEventReceiver to process the data. This will make it easy for you to maintain your code and debug. Below is the sample code to process the data. In this code itself, you can include the code to upload the data into database.

public class EmailHandler: SPEmailEventReceiver
{
public override void EmailReceived(
SPList objList,
SPEmailMessage objMessage,
string strReceiverData)
{
SPListItem objListItem = objList.Items.Add();
objListItem["Title"] = objMessage.Headers["Subject"];
objListItem["Body"] = objMessage.HtmlBody;
objListItem.Update();
}
}

Upvotes: 1

Related Questions