发送 RSS 源的共享邀请

共享邮件(包括共享邀请、共享请求和共享响应)在 Microsoft Outlook 中由 SharingItem] ( 表示。/../../api/Outlook.SharingItem.md) 对象。 NameSpace 对象的 CreateSharingItem 方法用于创建 SharingItem 对象,用于共享邀请和共享请求。 当调用表示共享邀请或共享请求的 SharingItemReplyReplyAll 方法时,Outlook 会自动创建共享响应。

本示例将使用 OpenSharingItem 方法创建一个代表真正简单的整合 (RSS) 源的共享邀请的 SharingItem。 共享后,收件人可以使用 NameSpace 对象的 OpenSharedFolder 方法或 SharingItem 对象的 OpenSharedFolder 方法打开 RSS 源。

  1. 此示例首先创建对 MAPI 命名空间的 ameSpace 对象引用。

  2. 之后,本示例将使用 CreateSharingItem 方法创建一个新的 SharingItem 对象,利用该 RSS 源的 URI 建立该 SharingItem 使用的共享上下文。

  3. 最后,调用新创建的 SharingItem 对象的 Recipients 集合的 Add 方法以添加指定的收件人,并使用 Send 方法发送 SharingItem

Public Sub ShareRSSByInvitation() 
 Dim oNamespace As NameSpace 
 Dim sRSSurl As String 
 Dim oSharingItem As SharingItem 
 
 On Error GoTo ErrRoutine 
 
 ' Specify the RSS feed URL for which sharing is to 
 ' be requested. 
 sRSSurl = "feed://example.com/rss.xml" 
 
 ' Get a reference to the MAPI namespace. 
 Set oNamespace = Application.GetNamespace("MAPI") 
 
 ' Create a new sharing request, using the RSS feed 
 ' URL to establish sharing context. 
 Set oSharingItem = oNamespace.CreateSharingItem(sRSSurl) 
 
 ' Add a recipient to the Recipients collection of 
 ' the sharing invitation. 
 oSharingItem.Recipients.Add "someone@example.com" 
 
 ' Send the sharing invitation. 
 oSharingItem.Send 
 
EndRoutine: 
 On Error GoTo 0 
 Set oSharingItem = Nothing 
 Set oFolder = Nothing 
 Set oNamespace = Nothing 
Exit Sub 
 
ErrRoutine: 
 Select Case Err.Number 
 Case 287 ' &H0000011F 
 ' The user denied access to the Address Book. 
 ' This error occurs if the code is run by an 
 ' untrusted application, and the user chose not to 
 ' allow access. 
 MsgBox "Access to Outlook was denied by the user.", _ 
 vbOKOnly, _ 
 Err.Number & " - " & Err.Source 
 Case -313393143 ' &HED520009 
 ' This error typically occurs if you set the 
 ' AllowWriteAccess property to true for a 
 ' default folder. 
 MsgBox Err.Description, _ 
 vbOKOnly, _ 
 Err.Number & " - " & Err.Source 
 Case -2147467259 ' &H80004005 
 ' This error typically occurs if the SharingItem 
 ' cannot be sent because of incorrect or 
 ' conflicting property settings. 
 MsgBox Err.Description, _ 
 vbOKOnly, _ 
 Err.Number & " - " & Err.Source 
 Case Else 
 ' Any other error that may occur. 
 MsgBox Err.Description, _ 
 vbOKOnly, _ 
 Err.Number & " - " & Err.Source 
 End Select 
 
 GoTo EndRoutine 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。