3

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..

UnderDog
  • 305
  • 1
  • 4
  • 14
Sander
  • 1,402
  • 2
  • 21
  • 44

1 Answers1

4

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);
Sander
  • 1,402
  • 2
  • 21
  • 44
  • Can you get this to work on Linux or are you running it on Windows? – frak Sep 23 '11 at 13:04
  • I used this on Windows, did not try it on Linux, but, I'll have to in the future, if you try it, please let me know if it worked for you. – Sander Sep 26 '11 at 17:15
  • 1
    I was getting null results, but my question here: http://stackoverflow.com/questions/7529388/php-ews-class-library-always-returns-null/ was answered and it turns out the account I was using did not have enough privilege – frak Sep 29 '11 at 15:15