Outlook ReportItem.Body returns corrupted coding for some users

Recently, we have a strange problem with Outlook that affects some users.

If some users automate Outlook Client to view backback / ReportItems returns in a shared mailbox, instead of returning the plain text of the message as indicated in the documentation, we will return a Unicode string that was parsed as a UTF-8 string - so it looks like Chinese.

Now I can get around this with some code, but an additional problem is that this change also occurs in Outlook, as well as for all users who have access to these mailboxes. The message itself, viewed in Outlook, looks like Chinese characters - the source code for unicode html is processed as UTF-8.

It seems like this might be a known issue, but I wanted to see if I could get some tips here.

We use the usual 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 text adorned with errors. In VBA, he tries to parse it as ASCII and returns a large "?" while in .Net it returns a value parsed as UTF-8, and we get characters that appear in Chinese. In any case, the original report item in the inbox begins to appear as Chinese characters and continues to do so for all users of this mailbox.

Any ideas?

UPDATE: I would like to share with this update, as it seems that some people still see this.

I want to quickly emphasize that the encoding problem is well discussed here and that access to the body of the message through the code is covered and quite easy. However, the encoding problem continues to exist in the Outlook client and has never been resolved, and this problem has been my constant task. There must be some error in the .Body property, which pushes the encoding of the original message object on the Exchange server. Good luck to everyone who needs to solve this problem.

UPDATE AGAIN: The answer and a more detailed description of the problem are posted below and are selected as the answer.

+6
source share
3 answers

Yes, there is a problem with the ReportItem.Body property in the Outlook object model (present in Outlook 2013 abd 2016) - you can see it in OutlookSpy : select the NDR message, click the "Element" button, select the "Body" property - it will be distorted. Worse, as soon as the report item touches OOM, Outlook will display the same garbage in the preview area.

The text of the report is stored in various properties of the MAPI recipient (click the "Message" button in OutlookSpy and go to the GetRecipientTable tab). The problem is that the ReportItem object does not provide a collection of recipients. The workaround is to use Extended MAPI (C ++ or Delphi) or Redemption (any language) - its ReportItem . The 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 
+3
source

I just happened to my VBA function in Outlook, which handles email e-mail responses for orders and marks these orders as requiring attention. The original message in Outlook looks great, but when I try to process it, the characters change to Chinese, and Report.Body just shows question marks.

I found that using StrConv to convert to Unicode can lead to the correct body contents for processing.

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

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

Most likely, you will try to apply an instance of the MailItem class to the ReportItem class. Is that the case?

I would also suggest using any low-level property viewer such as MFCMAPI or OutlookSpy to monitor properties at runtime. Do you see a "Chinese" character there?

0
source

Source: https://habr.com/ru/post/983769/


All Articles