Getting unread mail from exchange web services via

2019-03-31 05:22发布

问题:

How do you get all unread mail in a users' exchange mailbox using PHP while using this class ?

I figured to first list a folders contents like this:

$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);

Only then I get this error:

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

Is there anybody with experience with this class that can tell me what I'm doing wrong?

I do know that a string has to be passed, but it seems the class has just 3 constants without any functions or other properties..

回答1:

I figured it out, in above example I had to use

$request->Traversal = EWSType_FolderQueryTraversalType::DEEP;

Since it only had the 3 constants.

But posting it here since I think it might be useful for anyone else looking to do the same, listing all mail in your inbox goes as follows:

$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);