jamesiarmes / php-ews

PHP Exchange Web Services
http://jamesarmes.com/php-ews/
MIT License
567 stars 304 forks source link

Multiple mailboxes for the same user #404

Open gtorassa opened 7 years ago

gtorassa commented 7 years ago

Version (e.g. 1.0, dev-master): 1.0.0 PHP version: 5.5.9 Microsoft Exchange version: 2016

Description of problem: How can I access to different mailboxes associated to the same Exchange user? I can easily access to my INBOX (related to my personal account) but the FindFolders doesn't provide other mailboxes associated to my account.

Example request:

I found the followinf example in C and I think it could solve the problem, so I need to tranlsate it in PHP with the php-ews library:

var service = new ExchangeService();
service.Credentials = new WebCredentials("user_with_access@example.com", "password");
service.AutodiscoverUrl("a_valid_user@example.com");

var userMailbox = new Mailbox("target_user@example.com");
var folderId = new FolderId(WellKnownFolderName.Inbox, userMailbox);

Example response:

N.A.

Additional details:

I found a similar issue on Stackoverflow (http://stackoverflow.com/questions/25275060/access-another-mailbox-calendar-events-with-php-ews)

$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = 'email@address.com';

but it doesn't work because the DistinguishedFolderId class doesn't have a Mailbox child class.

boppy commented 6 years ago

Based on examples/folder/find.php:

$parent = new DistinguishedFolderIdType();
$parent->Id = DistinguishedFolderIdNameType::ROOT;

// New Properties:
$parent->Mailbox = new StdClass;
$parent->Mailbox->EmailAddress = 'secondMailAdress@yourDomain.org';
// End of new Props.

$request->ParentFolderIds->DistinguishedFolderId[] = $parent;

Works like a charme for me; also inside Office 365...

PS (edit): DistinguishedFolderId is an array - your code tries to access it like an object. So as a quickfix you can try (after setting DistinguishedFolderId)

- $request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass;
+ $request->ParentFolderIds->DistinguishedFolderId[0]->Mailbox = new StdClass;

- $request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = 'email@address.com';
+ $request->ParentFolderIds->DistinguishedFolderId[0]->Mailbox->EmailAddress = 'email@address.com';
tillmannschiffler commented 2 years ago

Hey guys,

thanks for the example - worked like a charm. I am connecting with some sort of company admin account and reading another calendar entries worked but now i am trying desperately to write into another calendar. My first ideas was like this:

        $parent = new DistinguishedFolderIdType();
        $parent->Id = DistinguishedFolderIdNameType::CALENDAR;
        $parent->Mailbox = new StdClass;
        $parent->Mailbox->EmailAddress = 'myClientAccount@somedomain.xyz';

        $request->ParentFolderId = $parent;

But all i got is the event is stored into the "admin" account and not into myClientAccount.

Maybe someone can give me a hint...or example?