SPEmailEventReceiver Class

Provides a method for trapping the event when a list receives an e-mail message.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPEmailEventReceiver

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public Class SPEmailEventReceiver

Dim instance As SPEmailEventReceiver
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPEmailEventReceiver

Remarks

An incoming e-mail event receiver must derive from this class and override the EmailReceived method.

Examples

The following code example shows how to use the SPEmailEventReceiver class in an event handler that responds to e-mail messages received in a list by adding an item to the list.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

namespace Example_Namespace
{
    public class Email_Handler: SPEmailEventReceiver
    {
        public override void EmailReceived(
            SPList oList,
            SPEmailMessage oMessage,
            string strReceiverData)
        {
            SPListItem oListItem = oList.Items.Add();
            oListItem["Title"] = oMessage.Headers["Subject"];
            oListItem["Body"] = oMessage.HtmlBody;
            oListItem.Update();
        }
    }
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

SPEmailEventReceiver Members

Microsoft.SharePoint Namespace