通过PHP从交换Web服务获取未读邮件

时间:2011-07-25 08:46:43

标签: php soap exchangewebservices php-ews

如何在使用this class时使用PHP在用户的交换邮箱中获取所有未读邮件?

我想首先列出像这样的文件夹内容:

$ews = new ExchangeWebServices("mailserver.domain.local", "user", "pass");

$request = new EWSType_FindFolderType();
$request->FolderShape = new EWSType_FolderResponseShapeType();
$request->FolderShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;

$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;

$request->Traversal = new EWSType_FolderQueryTraversalType();

$result = $ews->FindFolder($request);

var_dump($result);

只有这样我才会收到此错误:

Catchable fatal error: Object of class EWSType_FolderQueryTraversalType could not be converted to string

是否有任何有此课程经验的人可以告诉我我做错了什么?

我知道必须传递一个字符串,但似乎该类只有3个常量,没有任何函数或其他属性。

1 个答案:

答案 0 :(得分:4)

我想通了,在上面的例子中我必须使用

$request->Traversal = EWSType_FolderQueryTraversalType::DEEP;

因为它只有3个常数。

但是在此发布,因为我认为它可能对其他任何想要做同样事情的人有用,列出收件箱中的所有邮件如下:

$ews = new ExchangeWebServices("mailserver.domain.local", "user", "pass");

$request = new EWSType_FindItemType();
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;

$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;

$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;

$result = $ews->FindItem($request);