共用方式為


SPEmailEventReceiver class

提供方法來截獲事件清單會收到電子郵件訊息時。

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.SPEmailEventReceiver

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

Syntax

'宣告
Public Class SPEmailEventReceiver
'用途
Dim instance As SPEmailEventReceiver
public class SPEmailEventReceiver

備註

傳入的電子郵件事件接收者必須衍生自這個類別並覆寫EmailReceived方法。

Examples

下列程式碼範例示範如何在事件處理常式來回應接收清單中的項目加入至清單的電子郵件訊息中使用SPEmailEventReceiver類別。

這個範例要求using指示詞 (在 Visual Basic 的Imports ) 的Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空間。

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();
        }
    }
}
Namespace Example_Namespace
    Public Class Email_Handler
        Inherits SPEmailEventReceiver
        Public Overrides Sub EmailReceived(ByVal oList As SPList, ByVal oMessage As SPEmailMessage, ByVal strReceiverData As String)
            Dim oListItem As SPListItem = oList.Items.Add()
            oListItem("Title") = oMessage.Headers("Subject")
            oListItem("Body") = oMessage.HtmlBody
            oListItem.Update()
        End Sub
    End Class
End Namespace
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing 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.

請參閱

參照

SPEmailEventReceiver members

Microsoft.SharePoint namespace