使用 VBA 检索到截断的 Outlook 电子邮件 headers

Truncated Outlook email headers retrieved using VBA

我想在 Outlook 2010 中访问电子邮件 header。 我使用下面的代码,但不幸的是结果只包含 header 的前 252 个字符。对我做错了什么有什么建议吗?

Dim strHeader As String
strHeader = GetInetHeaders(olItem)
MsgBox "Truncated string: " & strHeader 

Function GetInetHeaders(olkMsg As Outlook.MailItem) As String
    ' Purpose: Returns the internet headers of a message.'
    ' Written: 4/28/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: 2007'
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
    Dim olkPA As Outlook.PropertyAccessor
    Set olkPA = olkMsg.PropertyAccessor
    GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
    Set olkPA = Nothing
End Function

PropertyAccessor class 有一些限制。其中之一是字符串属性的大小取决于信息存储类型。您需要使用低级 API - 扩展 MAPI 来读取不受 OOM 引入限制的属性。 IMAPIProp 接口的 OpenProperty 方法 returns 指向可用于访问 属性 的接口的指针。以下是 MSDN 库的内容:

The IMAPIProp::OpenProperty method provides access to a property through a particular interface. OpenProperty is an alternative to the IMAPIProp::GetProps and IMAPIProp::SetProps methods. When either GetProps or SetProps fails because the property is too large or too complex, call OpenProperty.

或者您可以考虑在扩展 MAPI 周围使用第三方包装器(例如,Redemption)。

Ms​​gbox 不是证明截断的好方法。文本可以被合法截断。

邮件项目中的文本似乎没有被截断。至少我没有注意到切断信息。

Private Sub Test_GetInetHeaders()

Dim olNewmail As mailItem
Dim strHeader As String
Dim olItem As mailItem

Set olItem = ActiveInspector.currentItem
strHeader = GetInetHeaders(olItem)

Set olNewmail = CreateItem(olMailItem)
olNewmail.body = strHeader
olNewmail.Display

MsgBox "Truncated string if limit exceeded: " & strHeader

ExitRoutine:
    Set olItem = Nothing
    Set olNewmail = Nothing

End Sub

Function GetInetHeaders(olkMsg As outlook.mailItem) As String
    ' Purpose: Returns the internet headers of a message.'
    ' Written: 4/28/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: 2007'
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
    Dim olkPA As outlook.propertyAccessor
    Set olkPA = olkMsg.propertyAccessor
    GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
    Set olkPA = Nothing
End Function