在我的 PHP 脚本中,我需要弄清楚如何检索在指定消息 ID 之后或在特定日期之后的所有电子邮件(两者都可以,我只需要检索自上次抓取收件箱以来的新电子邮件)。
这个收件箱每天收到数千封电子邮件,我在 30 天内无法删除任何电子邮件。对于最初的导入,我只是从收件箱的开头做一个偏移,但显然一旦我们开始清理电子邮件,这将不起作用。
我想我必须设置类“ EWSType_FindItemType ”的 $Restriction 属性,但我认为php-ews中不存在必要的类来执行此操作。我尝试自己添加它们,但我对 EWS 或 SOAP 的了解不够。
到目前为止,我唯一想到的是:
$Request->Restriction = new EWSType_RestrictionType();
$Request->Restriction->IsGreaterThan = new stdClass;
$Request->Restriction->IsGreaterThan->FieldURIOrConstant = new stdClass;
$Request->Restriction->IsGreaterThan->FieldURIOrConstant->Constant = '2012-01-02T07:04:00Z';
$Request->Restriction->IsGreaterThan->FieldURI = new stdClass;
$Request->Restriction->IsGreaterThan->FieldURI->FieldURI = 'item:DateTimeReceived';
那是行不通的:(
这是我目前用来检索电子邮件的代码:
<?php
require( dirname( __FILE__ ) . '/ews/ExchangeWebServicesLoader.php' );
$ews = new ExchangeWebServices( EXCHANGE_HOSTNAME, EXCHANGE_USERNAME, EXCHANGE_PASSWORD, ExchangeWebServices::VERSION_2010_SP1 );
$Request = new EWSType_FindItemType();
$Request->ItemShape = new EWSType_ItemResponseShapeType();
$Request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$Request->ItemShape->BodyType = EWSType_BodyTypeResponseType::TEXT;
$Request->ItemShape->BodyTypeSpecified = true;
$Request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
$Request->IndexedPageItemView = new EWSType_IndexedPageViewType();
$Request->IndexedPageItemView->MaxEntriesReturned = 25;
$Request->IndexedPageItemView->BasePoint = 'Beginning';
$Request->IndexedPageItemView->Offset = $offset;
$Request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$Request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$Request->ParentFolderIds->DistinguishedFolderId->Id = 'inbox';
$Request->ParentFolderIds->DistinguishedFolderId->Mailbox = new EWSType_EmailAddressType();
$Request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = 'sharedmailbox@company.org';
// sort order
$Request->SortOrder = new EWSType_NonEmptyArrayOfFieldOrdersType();
$Request->SortOrder->FieldOrder = array();
$order = new EWSType_FieldOrderType();
$order->FieldURI = new stdClass;
$order->FieldURI->FieldURI = 'item:DateTimeReceived';
$order->Order = 'Ascending';
$Request->SortOrder->FieldOrder[] = $order;
$response = $ews->FindItem($Request);
$items = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Message;
foreach ( $items as $item ) {
// Do stuff
}
任何帮助将不胜感激!