Is there a way to access someone's email and send on behalf of someone using the rest api? Any code examples will be helpful.
Do you mean like a delegate scenario, where you are authenticated as UserA but send mail on UserB's behalf? The REST API's don't currently support that scenario. The app can however access a user's email as that user (provided that the user themselves login and consent). You can also have an organizational admin consent for all users in their org by using the client credential flow.
UPDATE: We do now support delegate access via the REST APIs. In order to do it, your app must request new permission scopes.
If you're using the Azure v2 OAuth2 endpoints, there are new scopes that will enable this. So for example, if you access the user's mail with https://outlook.office.com/mail.read
, the scope that would get you the same access to delegate mailboxes would be https://outlook.office.com/mail.read.shared
.
If you're using the Azure v1 OAuth2 endpoints, then you need to modify the permissions set on your app registration. There are new permissions available that will include "and shared". For example, the permission that gives read access to the user's mail is "Read user mail". The permission for delegate access is "Read user and shared mail".
Once your app has the right permission, then accessing delegate data is very similar to how you access the user's data. The big difference is that you can't use the /me
URL segment, you must instead use /users/{user-id}
, with the user-id
set to the delegate.
For example, to access [email protected]'s inbox:
GET https://outlook.office.com/api/v2.0/users/[email protected]/mailFolders/inbox/messages