[英]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.