question

JelleTempelman-2549 avatar image
0 Votes"
JelleTempelman-2549 asked MichaelHan-MSFT commented

Sending mail in PHP application using Graph API not working

When trying to send a POST request to "/users/{email}/sendMail" I get an error 403 telling me
"Access is denied. Check credentials and try again."
But my application do have the right permissions (see screenshot)
135878-screenshot-2021-09-28-at-170159.png
Same goes the API explorer. It's telling me "You need to consent to permissions on the Modify permissions (preview) tab" but on the preview tab, all the permissions are consented.
135927-screenshot-2021-09-28-at-165516.png
What is going wrong?


microsoft-graph-mailazure-app-configurationmicrosoft-graph-applicationsmicrosoft-graph-explorer
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
1 Vote"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @JelleTempelman-2549,

You may misunderstand the delegated permissions and application permissions.

From the screenshot, your apps are using delegated permissions. And delegated permissions are used by apps that have a signed-in user present.

If you want you app run without a signed-in user present, you should use application permissions.

You could refer to this about delegated permissions and application permissions: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent#permission-types

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Auch... indeed I missed/misunderstood the differences in delegated/application permissions. I'm going to look into this later today! Thank you very very much for putting me on this track!

0 Votes 0 ·

Hi @MichaelHan-MSFT,
It works like a charm now. Thank you so much!

0 Votes 0 ·
MichaelHan-MSFT avatar image MichaelHan-MSFT JelleTempelman-2549 ·

@JelleTempelman-2549,

Glad that works for you! You could accept my answer if it helps you :)

0 Votes 0 ·
MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered JelleTempelman-2549 commented

Hi @JelleTempelman-2549,

Seems like you are trying send emaail from another user. To achieve this, mailbox permissions also need to be granted in exchange online. Please refer to this article for more: https://docs.microsoft.com/en-us/graph/outlook-send-mail-from-other-user

136163-image.png



If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


image.png (23.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MichaelHan-MSFT, thanks for responding. I hope we can work this out together, because I'm a bit lost...

I don't quite understand what you're implying. Under my Azure services -> App registrations I have an application. I'm trying to send email from my PHP web application using the API permissions of this Azure application. I don't understand what you mean with "sending mail from another user". That in my eyes seems a little weird, since my Azure application is not a user nor a mailbox itself, so I have no other choice than sending from "another" user.

0 Votes 0 ·
JelleTempelman-2549 avatar image
0 Votes"
JelleTempelman-2549 answered MichaelHan-MSFT converted comment to answer

Hi @MichaelHan-MSFT, thanks for responding. I hope we can work this out together, because I'm a bit lost...

I don't quite understand what you're implying. Under my Azure services -> App registrations I have an application. I'm trying to send email from my PHP web application using the API permissions of this Azure application. I don't understand what you mean with "sending mail from another user". That in my eyes seems a little weird, since my Azure application is not a user nor a mailbox itself, so I have no other choice than sending from "another" user.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.