c# - How to query Exchange mail server for email items? -
i trying upgrade en existing application reads exchange 2003 using webdav. mail server upgraded exchange 2013, checking how can use ews.
i have problem in although know inbox has unread items attachments, query running against finditems
object returning empty...
here code snippet:
private static void getattachments(exchangeservice service) { // return single item. itemview view = new itemview(100); servicepointmanager.servercertificatevalidationcallback = certificatevalidationcallback; exchangeservice service = new exchangeservice(exchangeversion.exchange2010_sp2);// .exchange2007_sp1); service.usedefaultcredentials = true; service.autodiscoverurl("bbtest@bocuk.local", redirectionurlvalidationcallback); itemview view = new itemview(1); string querystring = "hasattachments:true subject:'attachment test' kind:email"; // find first email message in inbox has attachments. // results in finditem operation call ews. finditemsresults<item> results = service.finditems(wellknownfoldername.inbox, querystring, view); //finditemsresults<item> results = service.finditems(wellknownfoldername.inbox, new itemview(50)); if (results.totalcount > 0) { // looping through emails (int16 idx = 0; idx < results.totalcount-1; idx++) { emailmessage email = results.items[idx] emailmessage; if (email.isread == false) { // request attachments on email message. results in getitem operation call ews. email.load(new propertyset(emailmessageschema.attachments)); foreach (attachment attachment in email.attachments) { if (attachment fileattachment) { fileattachment fileattachment = attachment fileattachment;
what supposed doing reading unread emails in target inbox (only 1 exchange server) , taking attachments on disk can add them attachments new cases on salesforce.
where going wrong?
also, line:
itemview view = new itemview(100);
was:
itemview view = new itemview(1);
surely 1 email item, right?
i submitted following xml , got expected results. easiest way figure out going on @ xml.
<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> <soap:header> <t:requestserverversion version="exchange2010_sp2"/> </soap:header> <soap:body> <finditem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" traversal="shallow"> <itemshape> <t:baseshape>idonly</t:baseshape> </itemshape> <parentfolderids> <t:distinguishedfolderid id="inbox"/> </parentfolderids> <querystring>hasattachments:true subject:'attachment test' kind:email</querystring> </finditem> </soap:body> </soap:envelope>
Comments
Post a Comment