简体   繁体   English

使用 VBA 检索截断的 Outlook 电子邮件标头

[英]Truncated Outlook email headers retrieved using VBA

I want to access the email headers in Outlook 2010. I use the code below but unfortunately the result contains only the first 252 characters of the header.我想访问 Outlook 2010 中的电子邮件标题。我使用下面的代码,但不幸的是结果只包含标题的前 252 个字符。 Any suggestion on what I'm doing wrong?关于我做错了什么的任何建议?

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

and

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

The PropertyAccessor class has some limitations. PropertyAccessor 类有一些限制。 One of them is that string properties are limited in size depending on the information store type.其中之一是字符串属性的大小取决于信息存储类型。 You need to use a low-level API - Extended MAPI for reading properties without limitations introduced by the OOM.您需要使用低级 API - 扩展 MAPI 来读取属性,而不受 OOM 引入的限制。 The OpenProperty method of the IMAPIProp interface returns a pointer to an interface that can be used to access a property. IMAPIProp接口的OpenProperty方法返回一个指向可用于访问属性的接口的指针。 Here is what MSDN library states:这是 MSDN 库声明的内容:

The IMAPIProp::OpenProperty method provides access to a property through a particular interface. IMAPIProp::OpenProperty 方法通过特定接口提供对属性的访问。 OpenProperty is an alternative to the IMAPIProp::GetProps and IMAPIProp::SetProps methods. OpenProperty 是 IMAPIProp::GetProps 和 IMAPIProp::SetProps 方法的替代方法。 When either GetProps or SetProps fails because the property is too large or too complex, call OpenProperty.当 GetProps 或 SetProps 由于属性太大或太复杂而失败时,调用 OpenProperty。

Or you may consider using third-party wrapper around Extended MAPI (for example, Redemption).或者您可以考虑在扩展 MAPI 周围使用第三方包装器(例如,Redemption)。

Msgbox is not a good method of proving truncation. Msgbox 不是证明截断的好方法。 Text can be legitimately truncated.文本可以被合法地截断。

Text in a mailitem does not appear to be truncated. mailitem 中的文本似乎没有被截断。 At least I do not notice cut off information.至少我没有注意到切断信息。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM