PHP-EWS 2010 how to set the IsRead flag

I was able to successfully get unread emails from my Exchange 2010 inbox using the php-ews API. However, after I received the emails, I want the IsRead property for the email to be true, so that these messages do not appear the next time the emails are received.

Has anyone done this before?

EDIT:

This is how I try to set the IsRead flag:

$message_id = ''; //id of message $change_key = ''; //change key $response = $ews->GetItem($request); //print_r($response);exit; if( $response->ResponseMessages->GetItemResponseMessage->ResponseCode == 'NoError' && $response->ResponseMessages->GetItemResponseMessage->ResponseClass == 'Success' ) { $a = array(); $message = $response->ResponseMessages->GetItemResponseMessage->Items->Message; $a['message_body'] = $message->Body->_; $a['sender'] = $message->From->Mailbox->EmailAddress; $a['subject'] = $message->ConversationTopic; $data[] = $a; //process the message data. $messageType = new EWSType_MessageType(); $messageType->IsRead = true; $path = new EWSType_PathToUnindexedFieldType(); $path->FieldURI = 'message:IsRead'; $setField = new EWSType_SetItemFieldType(); $setField->Message = $messageType; $setField->FieldURI = $path; $u = new EWSType_ItemChangeType(); $u->Updates = new EWSType_NonEmptyArrayOfItemChangeDescriptionsType(); $u->Updates->SetItemField = $setField; $u->ItemId = new EWSType_ItemIdType(); $u->ItemId->Id = $message_id; $u->ItemId->ChangeKey = $change_key; $updatedItems = new EWSType_NonEmptyArrayOfItemChangesType(); $updatedItems->ItemChange = $u; $updateMessenger = new EWSType_UpdateItemType(); $updateMessenger->ItemChanges = $updatedItems; $updateMessenger->MessageDisposition = 'SaveOnly'; $updateMessenger->ConflictResolution = 'AutoResolve'; try { $update_response = $ews->UpdateItem($updateMessenger); }catch (Exception $e){ echo $e->getMessage(); } } 

When I run the file, I get the following error:

 An internal server error occurred. The operation failed. 

After debugging for some time, I came to the conclusion that an error occurs in the curl_exec function in the NTLMSoapClient.php file.

I don’t know where to go next. Please, help.

+4
source share
3 answers

I encountered a similar problem when updating a calendar event and setting the IsAllDayEvent flag. This is the code that worked for me:

 $ews = new ExchangeWebServices(...); $request = new EWSType_UpdateItemType(); $request->ConflictResolution = 'AlwaysOverwrite'; $request->ItemChanges = array(); $change = new EWSType_ItemChangeType(); $change->ItemId = new EWSType_ItemIdType(); $change->ItemId->Id = $id; $change->ItemId->ChangeKey = $changeKey; $field = new EWSType_SetItemFieldType(); $field->FieldURI = new EWSType_PathToUnindexedFieldType(); $field->FieldURI->FieldURI = "calendar:IsAllDayEvent"; $field->CalendarItem = new EWSType_CalendarItemType(); $field->CalendarItem->IsAllDayEvent = true; $change->Updates->SetItemField[] = $field; $request->ItemChanges[] = $change; $response = $ews->UpdateItem($request); 

The biggest difference that I see here is that you do $u->Updates->SetItemField = $setField; whereas my code uses $u->Updates->SetItemField[] = $setField; .

Hope this helps.

Edit: You may have already seen this, but I based my code on the php-ews wiki .

0
source

I tried everything, including PathToExtendedFieldType, and it does not work in the final code below for me.

 $ews = new ExchangeWebServices('red', 'red', 'red',ExchangeWebServices::VERSION_2007_SP1); $request = new EWSType_UpdateItemType(); $request->SendMeetingInvitationsOrCancellations = 'SendToNone'; $request->MessageDisposition = 'SaveOnly'; $request->ConflictResolution = 'AlwaysOverwrite'; $request->ItemChanges = array(); // Build out item change request. $change = new EWSType_ItemChangeType(); $change->ItemId = new EWSType_ItemIdType(); $change->ItemId->Id = $contact_id; $change->ItemId->ChangeKey = $contact_change_key; #$change->Updates = new EWSType_NonEmptyArrayOfItemChangeDescriptionsType(); #$change->Updates->SetItemField = array(); // Build the set item field object and set the item on it. $field = new EWSType_SetItemFieldType(); $field->FieldURI = new EWSType_PathToUnindexedFieldType(); $field->FieldURI->FieldURI = "message:IsRead"; $field->Message = new EWSType_MessageType(); $field->Message->IsRead = true; $change->Updates->SetItemField[] = $field; $request->ItemChanges[] = $change; $response = $ews->UpdateItem($request); var_dump($response); 
0
source

Well, I don't know how to do this in php, but in C # there is another field that needs to be set: IsReadSpecified = true.

 email.IsRead = true; email.IsReadSpecified = true; 
0
source

Source: https://habr.com/ru/post/1433387/


All Articles