Search code examples
phpphp-ews

Garethp/php-ews: access two different mailboxes associated to the same MS exchange user


Lib: Garethp/php-ews

MS Exchange version: 2016

I have two mailboxes under the same login.

[email protected]

[email protected]

Authorization:

$ews = API::fromUsernameAndPassword('example.com', '[email protected]', 'some_pass');

I can reach all the folders from mail1, but don't know how to reach mail2 content.

Is there any way I can access those two different mailboxes associated to the same MS exchange user?

There was similar issue on GitHub, but different lib (jamesiarmes/php-ews): https://github.com/jamesiarmes/php-ews/issues/404

Any ideas?


Solution

  • There is a method setPrimarySmtpEmailAddress. So right after logging to email account, set the email address you want to access:

    $ews = API::fromUsernameAndPassword(
    'example.com', 
    '[email protected]', 
    'some_pass'
    )->setPrimarySmtpEmailAddress('[email protected]')->getMailbox();
    

    And that is pretty much it. Further actions stay the same: get the folders, read the emails, etc.