UniqueBody is not very unique?

I am trying to read the contents of an email message in HTML. My problem is that my body is not very unique, although I download EmailMessageSchema.UniqueBody .

Here is 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 examining my uniqueBody variable uniqueBody I can clearly see that it is not unique. It takes the entire text of the letter to the current letter (since the current letter is a response, I did not expect the contents of the email message to be sent to it).

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

So, how do I get a unique response text for a message, without its parent body?

+5
source share
2 answers

Explanation:

As stated in the documentation ( link here ), UniqueBody :

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

The bulk of this sentence is the idea of conversation : it is a concept from your inbox, not from a message. As a result, the UniqueBody field will only give you the very last part of the message after the original.

For the 1st message, even if it contains several messages (due to forwarding or replying), UniqueBody will contain everything.


Example:

I used my external address "mailA" to forward the message from "mailB" to "mailEWS", which will be the address where I request emails from EWS. I added a comment to this forward called "Forwarded Email Sample."

Here is what I got when I received a 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: mailA@gmail.com " target="_blank"> mailA@gmail.com </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 received the original message and comment forward.

Then: - mailEWS responses (text = "reply 1" - mailA responds to this answer (response text - "Reply from an external address")

So, I got a new message in my mailEWS inbox when I received 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 very last part of the message in the conversation, and not all the previous answers (but these elements are in the Body field)

+4
source

We can get a unique body using the code below.

 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; 
0
source

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


All Articles