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?
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.
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 <<a href="mailto:[email protected]" target="_blank">[email protected]</a>>:<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:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With