问题描述
我正在使用EWS从收件箱的电子邮件中单独读取电子邮件正文部分。
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.
例如
************
A This is good tenant.
Regards,
Test
From:[email protected]
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.
推荐答案
此方法使用 UniqueBody
为我工作:
// 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);
}
对于结果中的任何后续消息, 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.
请注意,可能会有更好的方法来执行此操作,但这在我的快速测试中(针对Exchange Online)有效。
Note that there might be better ways to do this, but this works in my quick test (against Exchange Online).
这篇关于如何使用Microsoft Exchange Web服务从特定电子邮件中读取最新的电子邮件对话HTML正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!