5

我已经能够使用 php-ews API 从 Exchange 2010 收件箱中成功检索未读电子邮件。但是,在我获取电子邮件后,我想将电子邮件的 IsRead 属性设置为 true,以便下次获取电子邮件时不会出现这些消息。

以前有人做过吗?

编辑 :

这就是我尝试设置 IsRead 标志的方式:

$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();
            }
        }

当我运行该文件时,出现以下错误:

An internal server error occurred. The operation failed.

经过一段时间的调试,我得出的结论是错误发生在 NTLMSoapClient.php 文件中的 curl_exec 函数处。

我不知道从这里开始。请帮忙。

4

3 回答 3

2

在更新日历事件和设置 IsAllDayEvent 标志时,我遇到了类似的问题。这是对我有用的代码:

$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);

我在这里看到的最大区别是您这样做$u->Updates->SetItemField = $setField;,而我的代码使用$u->Updates->SetItemField[] = $setField;.

我希望这有帮助。

编辑:您可能已经看过这个,但我的代码基于php-ews wiki中的代码。

于 2012-09-17T14:31:55.057 回答
0

我尝试了包括 PathToExtendedFieldType 在内的所有方法,但它在下面为我工作的最终代码中不起作用

$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);
于 2012-10-02T10:07:36.907 回答
-1

好吧,我不知道它在 php 中如何,但在 C# 中还有另一个字段,必须设置:IsReadSpecified = true。

email.IsRead = true;
email.IsReadSpecified = true;
于 2013-05-14T11:53:42.053 回答