问题
I am using EWS to read email body part alone from email of inbox.
I need to extract only replied email body instead of whole email body.
e.g.
************
A This is good tenant.
Regards,
Test
From:test@gmail.com
To: ----
----------
----------
Hi User, Data has been populated. Please reply with A or R with comments.
Regard
Admin.
************
So when I read email body of above email I get the whole body mentioned above. But what I need is only:
************
A This is good tenant.
Regards,
Test
************
which is having latest replied email body only.
回答1:
This approach with UniqueBody
works for me:
// ensure that username, password, domain and smtpAddress are set
var service = new ExchangeService {
PreAuthenticate = true,
Credentials = new WebCredentials(username, password, domain),
};
service.AutodiscoverUrl(smtpAddress, redirect => true);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, smtpAddress);
var inbox = Folder.Bind(service, new FolderId(WellKnownFolderName.Inbox));
var fir = inbox.FindItems(new ItemView(10));
foreach (var ir in fir) {
var msg = EmailMessage.Bind(service, ir.Id, new PropertySet(EmailMessageSchema.UniqueBody));
Console.WriteLine(msg.UniqueBody.Text);
}
For any follow-up message in the results, the msg.UniqueBody.Text
property contains only the parts that are new in that message.
Note that there might be better ways to do this, but this works in my quick test (against Exchange Online).
来源:https://stackoverflow.com/questions/25603535/how-to-read-latest-email-conversation-html-body-from-specific-email-using-micros