How to read latest email conversation HTML body from specific email using Microsoft Exchange webservice

旧街凉风 提交于 2020-01-03 05:32:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!