[英]Truncated Outlook email headers retrieved using VBA
我想访问 Outlook 2010 中的电子邮件标题。我使用下面的代码,但不幸的是结果只包含标题的前 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 类有一些限制。 其中之一是字符串属性的大小取决于信息存储类型。 您需要使用低级 API - 扩展 MAPI 来读取属性,而不受 OOM 引入的限制。 IMAPIProp
接口的OpenProperty方法返回一个指向可用于访问属性的接口的指针。 这是 MSDN 库声明的内容:
IMAPIProp::OpenProperty 方法通过特定接口提供对属性的访问。 OpenProperty 是 IMAPIProp::GetProps 和 IMAPIProp::SetProps 方法的替代方法。 当 GetProps 或 SetProps 由于属性太大或太复杂而失败时,调用 OpenProperty。
或者您可以考虑在扩展 MAPI 周围使用第三方包装器(例如,Redemption)。
Msgbox 不是证明截断的好方法。 文本可以被合法地截断。
mailitem 中的文本似乎没有被截断。 至少我没有注意到切断信息。
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.