Skip to content
Advertisement

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.

mail1@example.com

mail2@example.com

Authorization:

$ews = API::fromUsernameAndPassword('example.com', 'mail1@example.com', '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?

Advertisement

Answer

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', 
'mail1@example.com', 
'some_pass'
)->setPrimarySmtpEmailAddress('mail2@example.com')->getMailbox();

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

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement