c# - EWS managed API. IsNew Always return false and can't use TextBody -


i newbie developer , have been stuck ews hours now. need read through recent emails, unread emails , use data them stuff.

at moment code looks this.

static void main(string[] args)     {         servicepointmanager.servercertificatevalidationcallback = certificatevalidationcallback;         exchangeservice service = new exchangeservice(exchangeversion.exchange2013);         service.credentials = new webcredentials("support@mycompany.com", "mysupersuperdupersecretpassword");           service.autodiscoverurl("support@mycompany.com", redirectionurlvalidationcallback);           finditemsresults<item> findresults = service.finditems(wellknownfoldername.inbox,new itemview(2));         foreach (item item in findresults.items)         {             // works until here             console.writeline(item.subject);             console.writeline('\n');             item.load();             string temp = item.body.text;             // can't seem textbody work. used regex                                                 match match = regex.match(temp, "<body>.*?</body>", regexoptions.singleline);             string result = match.value;             result = result.replace("<body>", "");             result = result.replace("</body>", "");             console.write(result);             console.writeline('\n');             //now email boddy fine isnew returns false.             if (item.isnew)             {                 console.writeline("this message unread!");             }             else             {                 console.writeline("this message read!");             }         }               } 

i have googled , tried , googled more , stuck. how emails read, there way email body text that's more effective have done ? super appreciated.

the msdn article usage pretty if haven't read it.

for issue, cast item emailmessage

foreach (item item in findresults.items) {     var mailitem = (emailmessage)item;     // works until here     console.writeline(mailitem.subject); } 

i did notice not using property sets, having used ews event notifications , not going through existing mails, may different.

update additions in light of changes

use property set

new propertyset(basepropertyset.firstclassproperties) {     requestedbodytype = bodytype.text }; 

also reads little nicer , uses body.text property

foreach (item myitem in findresults.items.where(i=>i emailmessage)) {     var mailitem = myitem emailmessage;     console.writeline(mailitem.subject);     mailitem.load(new propertyset(basepropertyset.firstclassproperties) {         requestedbodytype = bodytype.text     }); // adding parameter trick :)     console.writeline(mailitem.body.text);      if(! mailitem.isread)         console.writeline("who daddy!!!!");  } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -