UniqueBody is not very unique?
Asked Answered
O

2

7

I'm trying to read the content of an email in HTML. My problem though, is that my body is not very unique though I'm loading the EmailMessageSchema.UniqueBody.

Here's my expected solution:

var props = new PropertySet(BasePropertySet.IdOnly, 
    EmailMessageSchema.UniqueBody,
    EmailMessageSchema.Subject,
    EmailMessageSchema.To,
    EmailMessageSchema.From
    /*Futher properties if needed*/);

props.RequestedBodyType = BodyType.HTML;

var message = EmailMessage.Bind(subscription.Service, item.ItemId, props);

// Should be unique
var uniqueBody = message.UniqueBody.Text;

When debugging and investigate my uniqueBody variable, I can clearly see that this is not unique. It takes the entire body of the email prior to the current email (as the current email is a response, i wouldn't expect to get the content of the email responded to).

I'm not sure I understand the concept of the EmailMessageSchema.UniqueBody property, or perhaps I'm simply doing something wrong?

So, how do I get the unique body of a reply email, without it's parents body?

Offcolor answered 13/3, 2017 at 11:58 Comment(3)
Looks like you're not the only one social.msdn.microsoft.com/Forums/en-US/…Drury
Added a reply a few days ago, any comments?Hamann
I am no longer working with this, so I'll just leave this SO here for future references.Offcolor
H
8

Explanation:

As defined in the documentation (link here), UniqueBody is:

the body part that is unique to the conversation that this item is part of

The main part of this sentence is the idea of conversation: it is a notion from your mailbox, not from the message. As a consequence, the field UniqueBody will give you only the newest part of a message after an initial one.

For the 1st message, even if it includes several messages (due to a forward or reply), UniqueBody will contain everything.


Sample:

I used my external address "mailA" to forward a message from "mailB" to "mailEWS" which will be the address where I query emails with EWS. I added a comment on this forward, named "Forwarded email sample".

Here is what I got when getting the message in "mailEWS":

<html>
   <body>
      <div>
         <div>
            <div dir="ltr">
               <span dir="ltr">
                  Forwarded email sample
                  <div>
                     <br>
                     <div>
                        Test from MailB &lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;:<br>
                        <div style="margin:0 0 0 0.8ex;padding-left:1ex;border-left:1px solid #CCCCCC;">Dear user,<br>
                           <br>
                           Content of initial email from mailB<br>
                           <br>
                           Sincerely,<br>
                           Test<br>
                        </div>
                     </div>
                  </div>
               </span>
            </div>
         </div>
      </div>
   </body>
</html>

As you can see I got the original message and the comment on the forward.

Then:

  • mailEWS replies (text = "reply 1"
  • mailA replies on that reply (reply text is "Reply from external address")

So I got a new message in my mailEWS mailbox, when getting the UniqueBody with EWS:

<html>
   <body>
      <div>
         <div>
            <div dir="ltr"><span dir="ltr">Reply from external address</span></div>
            <div><br>
            </div>
         </div>
      </div>
   </body>
</html>

As you can see, I get only the newest part of the message in the conversation, not all the previous replies (but those items are in Body field)

Hamann answered 2/10, 2017 at 12:3 Comment(0)
C
0

We can get the Unique body by using below code.

var props = new PropertySet(BasePropertySet.FirstClassProperties, 
    EmailMessageSchema.UniqueBody,
    EmailMessageSchema.Subject,
    EmailMessageSchema.To,
    EmailMessageSchema.From

props.RequestedBodyType = BodyType.HTML;

var message = EmailMessage.Bind(subscription.Service, item.ItemId, props);

// Should be unique
var uniqueBody = message.UniqueBody.Text;
Convery answered 12/7, 2019 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.