4

我正在使用 php-ews 来读取交换邮箱。但是,我想从收件箱中选择一封电子邮件并回复该电子邮件,其中包含电子邮件历史记录并发送回复。下面是我用来从收件箱中获取特定电子邮件的代码。

$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/>';

现在我已经收到要回复的消息,我该如何进一步处理并起草回复消息并为此电子邮件创建回复项目。

我已经在谷歌上搜索过这个,但没有运气。

钻了几个小时的 php-ews 类,我看了 EWSType_ReplyAllToItemType、EWSType_PostReplyItemType、EWSType_PostReplyItemBaseType 等,但无法理解如何使用这些代码。

请帮助伙计们!任何帮助将不胜感激。

我相信对这篇文章的任何回复都会有所帮助,因为没有论坛讨论这个问题。:)

谢谢你。

4

2 回答 2

3

终于找到了关于如何使用 PHP-EWS 回复电子邮件的答案。

首先,我们需要修改 EWSType/MessageType.php 并在关闭类之前在类的末尾添加以下行:

public $NewBodyContent;

回复功能如下:

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;

    }

这将向指定的 ID 和 ChangeKey 发送回复

于 2013-08-27T12:23:17.443 回答
1

你不能简单地向你要回复的电子邮件的回复地址发送一封新电子邮件吗?

https://github.com/jamesiarmes/php-ews/wiki/Email:-Send-Email

将主题设置为Re: <subject of previous message>

然后简单地将原始电子邮件的正文包含在响应正文的下方?

于 2013-01-21T13:42:30.303 回答