Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get message id and change key after send a message? #593

Open
winds1983 opened this issue Nov 4, 2020 · 1 comment
Open

How to get message id and change key after send a message? #593

winds1983 opened this issue Nov 4, 2020 · 1 comment

Comments

@winds1983
Copy link

winds1983 commented Nov 4, 2020

Version (e.g. 1.0, dev-master): dev-master
PHP version: php 7.3
Microsoft Exchange version: exchange 2016

Description of problem:
Cannot get message id and change key after send message, I want use these info to reply next time.

Example request:

protected function _sendMessage($messageId, $changeKey)
    {
        // Build the request.
        $request = new SendItemType();
        $request->SaveItemToFolder = true;
        $request->ItemIds = new NonEmptyArrayOfBaseItemIdsType();

        // Add the message to the request.
        $item = new ItemIdType();
        $item->Id = $messageId;
        $item->ChangeKey = $changeKey;
        $request->ItemIds->ItemId[] = $item;

        // Configure the folder to save the sent message to.
        $send_folder = new TargetFolderIdType();
        $send_folder->DistinguishedFolderId = new DistinguishedFolderIdType();
        $send_folder->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::SENT;
        $request->SavedItemFolderId = $send_folder;

        $response = $this->client->SendItem($request);

        $result = [];

        // Iterate over the results, printing any error messages.
        $response_messages = $response->ResponseMessages->SendItemResponseMessage;
        foreach ($response_messages as $response_message) {
            // Make sure the request succeeded.
            if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
                $code = $response_message->ResponseCode;
                $message = $response_message->MessageText;

                $result['response'][] = [
                    'code' => $response_message->ResponseCode,
                    'message' => $response_message->MessageText,
                ];
                \Yii::error("Message failed to create with \"$code: $message\"\n");

                continue;
            }

            $result['items'][] = $response_message;
            \Yii::info("Message sent successfully.\n");
        }
        
        return $result;
    }

Example response:

array:1 [▼
  0 => jamesiarmes\PhpEws\Response\ItemInfoResponseMessageType {#207 ▼
    +Items: jamesiarmes\PhpEws\ArrayType\ArrayOfRealItemsType {#208 ▼
      +CalendarItem: []
      +Contact: []
      +DistributionList: []
      +Item: []
      +MeetingCancellation: []
      +MeetingMessage: []
      +MeetingRequest: []
      +MeetingResponse: []
      +Message: []
      +PostItem: []
      +Task: []
    }
    +DescriptiveLinkKey: 0
    +MessageText: "The specified object was not found in the store., The process failed to get the correct properties."
    +MessageXml: null
    +ResponseClass: "Error"
    +ResponseCode: "ErrorItemNotFound"
  }
]

Additional details:
I built a draft message, it can get the message id and change key, then use it to send message successfully. but can use this message id and change key to reply. and throw this error:

The specified object was not found in the store., The process failed to get the correct properties.

How to get message id and change key after send a message?

@winds1983
Copy link
Author

@jamesiarmes Could you give me some solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant