For an app-only, certificate-based Azure Function that sends mail from a shared mailbox via Microsoft Graph, configure Exchange Online and Graph so the app can send as that mailbox and call the correct Graph endpoint.
With Microsoft Graph application permission Mail.Send, Exchange Online treats the app as being allowed to send mail as any user unless restricted. The app can then send mail from:
- A dedicated mailbox, or
- Any shared mailbox, by targeting that mailbox in the Graph call.
The app-only access example shows that when Mail.Send is granted and consented, a POST to:
POST /users/{id | userPrincipalName}/sendMail
returns 200 – Access granted. Admin allowed the app to send mail as any user.
This applies equally to a shared mailbox if it is an Exchange Online mailbox.
If the organization wants to restrict which mailboxes the app can use, configure an application access policy for the app so it can only send as specific mailboxes (for example, only the shared mailbox). This is done in Exchange Online/Graph, but the details are outside the provided context.
2. Send As / Send on Behalf permissions for the app
For Graph application permission Mail.Send, Exchange Online checks whether the client app has that app role. If it does, the call succeeds for /users/{mailbox}/sendMail.
No additional per-mailbox Send As or Send on Behalf assignment is required for the app itself when using Mail.Send application permission, because the permission already means “send mail as any user” at the service level. Traditional Send As / Send on Behalf assignments (for example, via Set-Mailbox -GrantSendOnBehalf) are for user or shared mailbox delegates, not for app-only Graph access.
3. Correct Microsoft Graph endpoint for shared mailbox
To send from a shared mailbox, use the user-specific endpoint and set the from address to the shared mailbox:
POST /users/{sharedMailboxUPN}/sendMail
The message body should specify the shared mailbox in the from property:
{
"message": {
"subject": "Subject here",
"body": {
"contentType": "HTML",
"content": "Body here"
},
"toRecipients": [
{
"emailAddress": {
"address": "******@contoso.com"
}
}
],
"from": {
"emailAddress": {
"address": "******@contoso.com"
}
}
}
}
The shared mailbox example in the documentation uses this pattern: set the from property to the address to send from; Graph sets sender automatically based on mailbox permissions.
Do not use /me/sendMail in an app-only scenario, because there is no signed-in user; /me is for delegated permissions.
4. Additional configuration beyond Mail.Send
From the provided context:
-
Mail.Send application permission, with admin consent, allows the app to send mail as any user.
- Optionally, use application access policies to limit which mailboxes the app can access, even with
Mail.Send.
No additional Graph permissions are required just to send mail from a shared mailbox. User.Read.All is not required for sending, but can be used if the app needs to look up users.
5. Best practices and common pitfalls
Best practices
- Use application access policies to restrict the app to only the shared mailbox (and any other required mailboxes) so it cannot send as every user.
- Use a dedicated shared mailbox for automated mail (for example,
******@contoso.com) to separate automation from human users.
- Use app-only authentication with certificate as already configured, and avoid storing secrets in code.
- Set the
from address explicitly in the message to the shared mailbox address.
Common pitfalls
- Calling
/me/sendMail in an app-only context (fails because there is no delegated user).
- Forgetting to set the
from property when sending from a group or shared mailbox.
- Granting
Mail.Send application permission without restricting it via application access policies, which allows sending as any mailbox in the tenant.
In summary:
- Keep
Mail.Send application permission with admin consent.
- Optionally configure application access policies to restrict the app to the shared mailbox.
- Use
POST /users/{sharedMailboxUPN}/sendMail and set from to the shared mailbox address.
- No additional
Send As / Send on Behalf mailbox permissions are required for the app when using Mail.Send application permission.
References: