Reputation: 2728
I am using php-ews for reading the exchange mailbox. However, i would like to pick an e-mail from the inbox and reply to that e-mail, with the email history and send the response. Below is the code that i am using to get the specific email from the Inbox.
$ews = new ExchangeWebServices($account_array['server'], $account_array['username'], $account_array['password'], ExchangeWebServices::VERSION_2010_SP1);
$message_id = 'AAMkADU3ZDdmZmY3LWI3OGMtNDRmMy1hYTdlLTBlZjkwOGE3NTU5MwBGAAAAAADkJRKCdlaES7sRqf3veO/UBwCgoREk6zyqQqi6KC/gJMy0AAAAvGoCAACgoREk6zyqQqi6KC/gJMy0AAAAvGpQAAA=';
$change_id = 'CQAAABYAAACgoREk6zyqQqi6KC/gJMy0AAAAvMEZ';
$request = new EWSType_GetItemType();
$request -> ItemShape = new EWSType_ItemResponseShapeType();
$request -> ItemShape -> BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request -> ItemShape -> BodyType = EWSType_BodyTypeResponseType::HTML;
$body_property = new EWSType_PathToUnindexedFieldType();
$body_property -> FieldURI = 'item:Body';
$request -> ItemShape -> AdditionalProperties = new EWSType_NonEmptyArrayOfPathsToElementType();
$request -> ItemShape -> AdditionalProperties -> FieldURI = array($body_property);
$request -> ItemIds = new EWSType_NonEmptyArrayOfBaseItemIdsType();
$request -> ItemIds -> ItemId = array();
$message_item = new EWSType_ItemIdType();
$message_item -> Id = trim($message_id);
$request -> ItemIds -> ItemId[] = $message_item;
$response = $ews -> GetItem($request);
//print '<pre>' . print_r($response, true) . '</pre><hr/>';
$message = $response -> ResponseMessages -> GetItemResponseMessage -> Items -> Message;
print '<pre>' . print_r($message, true) . '</pre><hr/>';
Now that i have got the message to reply to, how do i take this further and draft a response message and create a Reply Item for this email.
I have searched Google for this, but no luck.
Drilling into the php-ews classes for hours, i took a look at EWSType_ReplyAllToItemType, EWSType_PostReplyItemType, EWSType_PostReplyItemBaseType, etc. but unable to understand how to use these codes.
Please help guys! any helps would be greatly appreciated.
I am sure that any response to this post would be helpful since there are no forums talking about this. :)
Thank You.
Upvotes: 4
Views: 1671
Reputation: 2728
Finally found an answer on how to ReplyTo an E-mail using PHP-EWS.
Firstly, we need to modify EWSType/MessageType.php and add the below line at the end of the class just before closing of the class:
public $NewBodyContent;
and the reply function goes as:
Public function replyToMessage($id,$changeKey)
{
$ews = new ExchangeWebServices($this->server_url, $this->username, $this->password, ExchangeWebServices::VERSION_2010_SP1);
//$msg = new EWSType_ReplyAllToItemType();
$msg = new EWSType_MessageType();
//In Case you need to add anyone in CC
$cc = new EWSType_ArrayOfRecipientsType();
$cc->Mailbox = new EWSType_EmailAddressType();
$cc->Mailbox->EmailAddress = 'emailaddresshere';
$cc->Mailbox->Name = 'displaynamehere';
$msg->CcRecipients = $cc;
$msg->ReferenceItemId = new EWSType_ItemIdType();
$msg->ReferenceItemId->Id = $id;
$msg->ReferenceItemId->ChangeKey = $changeKey;
$msg->NewBodyContent = new EWSType_BodyType();
$msg->NewBodyContent->BodyType = 'HTML';
$msg->NewBodyContent->_ = 'HTML Content Goes Here';
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->ReplyAllToItem = $msg;
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = TRUE;
$response = $ews->CreateItem($msgRequest);
return $response->ResponseMessages->CreateItemResponseMessage->ResponseCode;
}
This will send a Reply to the specified ID and ChangeKey
Upvotes: 3
Reputation: 846
Can you not simply send a new email to the reply address of the email you want to reply to?
https://github.com/jamesiarmes/php-ews/wiki/Email:-Send-Email
Set the subject to Re: <subject of previous message>
And then simply include the body of the original email underneath the body of the response?
Upvotes: 1