'Outlook ReportItem.Body returning messed up encoding

If certain users automate the Outlook Client to view bounce backs/ReportItems in a shared inbox, rather than returning the clear text of the message as indicated by the documentation there is a unicode string that has been parsed as a UTF-8 string - so it looks like Chinese.

I can get past that with some code, but the additional issue is that this change occurs in Outlook as well for all users with access to that inbox. The message itself as viewed in Outlook appears as Chinese characters - the original unicode html parsed as UTF-8.

We are using the normal methods to access the report item:

For Counter as Integer = Inbox.Items.Count To 1 Step -1
    Dim Report As Outlook.ReportItem = Inbox.Items(Counter)
    Dim Body As String = Report.Body

The last line is where we get the garbled text In VBA it attempts to parse it as ASCII and returns a large block of "?". In .Net it returns the value parsed as UTF-8 and we get the characters that appear Chinese. In either case the report item in the inbox begins displaying as Chinese characters and continues to do so for all users of that inbox.



Solution 1:[1]

I just had this happen to my VBA function in Outlook that processes email bounce backs for orders and marks those orders as requiring attention. The original email in outlook looks fine but when I attempt to process it, the characters change to Chinese and Report.Body just shows question marks.

I found using StrConv to convert to Unicode could get me the correct body contents for processing.

Dim strBody as String
strBody = StrConv(Report.Body, vbUnicode)

Solution 2:[2]

Are you sure that the Inbox.Items(Counter) call returns an instance of the ReportItem class? Did you have a chance to check out the MessageClass property?

Most probably you try to cast an instance of the MailItem class to the ReportItem class. Is that the case?

Also I'd suggest using any low-level property viewer such as MFCMAPI or OutlookSpy for observing properties at runtime. Do you see "chinese" charactere there?

Solution 3:[3]

I came across this issue and I've written a function that solves the issue for me. I thought I'd share it here in case it's of use to anyone else.

Private Sub Example()
    Dim Item As Object
    
    Set Item = Application.ActiveExplorer.Selection(1)
    
    Debug.Print ItemBody(Item)
End Sub

Public Function ItemBody(Item As Variant) As String
On Error Resume Next
    If TypeName(Item) = "ReportItem" Then
        With Item.GetInspector
            ItemBody = .WordEditor.Content
            .Close 1
        End With
    Else
        ItemBody = Item.Body
    End If
End Function

Solution 4:[4]

Yes, there is a problem with ReportItem.Body property in the Outlook Object Model (present in Outlook 2013 and 2016) - you can see it in OutlookSpy (I am its author): select an NDR message, click Item button, select the Body property - it will be garbled. Worse than that, once the report item is touched with OOM, Outlook will display the same junk in the preview pane.

The report text is stored in various MAPI recipient properties (click IMessage button in OutlookSpy and go to the GetRecipientTable tab). The problem is the ReportItem object does not expose the Recipients collection. The workaround is to either use Extended MAPI (C++ or Delphi) or Redemption (any language - I am also its author) - its ReportItem.ReportText property does not have this problem:

set oItem = Application.ActiveExplorer.Selection(1)
set oSession = CreateObject("Redemption.RDOSession")
oSession.MAPIOBJECT = Application.Session.MAPIOBJECT
set rItem = oSession.GetRDOObjectFromOutlookObject(oItem)
MsgBox rItem.ReportText

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bluey
Solution 2 Eugene Astafiev
Solution 3 Sam
Solution 4 Dmitry Streblechenko