README Send As / On Behalf Of #
Overview #
Sends an email that appears to come from an alias address, shared mailbox, distribution group, or Microsoft 365 group rather than the authenticated user’s own address. Authentication is via OAuth2 with MFA support using VBAuth.dll. The mechanism is a standard POST /me/sendMail with a from field added to the message payload containing the alias address. The Mail.Send.Shared delegated scope is required — Mail.Send alone is insufficient.
Exchange Online inspects the from address against its own permission store and determines whether the result is Send As or Send on Behalf Of. Graph cannot pre-verify which permission applies, nor whether either exists — the send attempt itself is the test. A 403 ErrorSendAsDenied response means the authenticated user has neither permission on that address.
Send As vs Send on Behalf Of — what Exchange decides #
Both permissions are granted in Exchange, not in Azure Entra. The Graph API call is identical for both; Exchange enforces the distinction:
Send on Behalf Of The recipient sees “From: Alias Address on behalf of Authenticated User”. Both addresses are visible. Granted per-mailbox via Outlook delegate settings or Exchange admin centre. Available for user mailboxes, shared mailboxes, and Microsoft 365 groups.
Send As
The recipient sees only “From: Alias Address” — the authenticated user’s identity is completely hidden. The message is indistinguishable from one sent directly from that mailbox. Granted via Exchange admin centre or PowerShell (Add-RecipientPermission). Available for user mailboxes and shared mailboxes. Not available for distribution groups or mail-enabled security groups — those support Send on Behalf Of only.
Exchange caches mailbox permissions for performance. After a permission is granted or changed, allow up to an hour before testing — if it fails immediately after granting, wait and retry.
Shared mailboxes, distribution groups, and Microsoft 365 groups #
The same from field mechanism covers all three scenarios:
Shared mailbox — set from.emailAddress.address to the shared mailbox SMTP address. The authenticated user must have either Send As (preferred for shared mailboxes) or Send on Behalf Of granted in Exchange. Mail.Send.Shared scope is required.
Distribution group / mail-enabled security group — set from.emailAddress.address to the group SMTP address. Only Send on Behalf Of is available for groups — Send As cannot be granted. The group owner or an Exchange admin must grant Send on Behalf Of via PowerShell: Set-DistributionGroup -Identity group@domain.com -GrantSendOnBehalfTo user@domain.com.
Microsoft 365 group — set from.emailAddress.address to the group SMTP address. Send on Behalf Of only, granted via: Set-Mailbox -GroupMailbox group@domain.com -GrantSendOnBehalfTo user@domain.com.
In all three cases the API call is identical. Only the Exchange-side permission setup differs.
Note on saved sent items #
When saveToSentItems is true, the sent message is saved to the authenticated user’s Sent Items, not the alias mailbox’s Sent Items. Exchange administrators can configure the alias mailbox to also receive a copy via the “always save a copy” setting, but this is outside the scope of the API call.
Office apps #
- Access (tested M365)
- Excel (untested M365)
Required components #
- VBAuth.dll v1.x
- modVBAuthGlobalConstants.bas (from /shared)
- modSendAsEmail.bas (this module)
Azure Entra App Registration #
Delegated permissions:
- Mail.Send.Shared
Note: Mail.Send.Shared is a separate scope from Mail.Send and requires its own app registration.
VBAuth Admin Table – Required Values #
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | 19 | Identifies this feature’s configuration record |
| ActionName | VBAuth – Send As / On Behalf Of | Display name — any value acceptable |
| ClientID | (your App Client ID) | GUID from Azure App Registration Overview blade |
| TenantID | (your Tenant ID) | GUID from Azure App Registration Overview blade |
| ObjectID | (your Object ID) | Set by PopulateMissingObjectIDs |
| ScopeClaims | Mail.Send.Shared | Comma-separated Graph scopes |
| Verb | POST | HTTP method |
| URLPart1 | https://graph.microsoft.com/v1.0/me/sendMail | Graph endpoint |
| URLParameter1 | NO VALUE REQUIRED | Not used |
| URLPart2 | NO VALUE REQUIRED | Not used |
| URLParameter2 | NO VALUE REQUIRED | Not used |
| URLPart3 | NO VALUE REQUIRED | Not used |
| WaitForLogin | 60 | Seconds — NB MSXML2 timeout parameters are in milliseconds |
Module: modSendAsEmail.bas #
Public functions #
Public Function SendAsEmail( _
ByVal strFrom As String, _
ByVal strTo As String, _
ByVal strCC As String, _
ByVal strBCC As String, _
ByVal strSubject As String, _
ByVal strBody As String, _
ByVal blnSaveToSentItems As Boolean, _
ByRef strMessage As String) As Boolean
Code language: JavaScript (javascript)
Sets AppID=19, acquires a Mail.Send.Shared bearer token, builds the JSON payload with from set to strFrom, and POSTs to /me/sendMail. Returns True on HTTP 202. On HTTP 403, strMessage contains a detailed explanation of the Exchange permission requirement.
Private functions #
JsonEscape(strValue)— escapes special characters for JSON string embedding.BuildRecipientArray(strAddresses)— converts comma/semicolon address lists to Graph recipient array JSON.BuildSendAsPayload(...)— constructs the complete JSON payload including thefromfield.
Behaviour #
- Runs as the signed-in user (delegated permissions only).
- HTTP 202 Accepted is the success code — no response body is returned.
- HTTP 403 ErrorSendAsDenied means Exchange has denied the send. The authenticated user lacks both Send As and Send on Behalf Of permission on the alias mailbox. This is an Exchange configuration issue, not an API or Azure issue.
- Graph cannot determine in advance which permission (Send As or Send on Behalf Of) is in effect, or whether either exists. The send attempt is the only verification mechanism available.
- Authentication is interactive on first run; subsequent calls within the session reuse the cached token.
Notes #
Mail.Send.Sharedmust be granted admin consent before users can authenticate.- Exchange permission changes can take up to an hour to take effect due to caching.
- For shared mailboxes, Send As is generally preferable to Send on Behalf Of as it presents a cleaner “from” address to recipients.
- Distribution groups and Microsoft 365 groups only support Send on Behalf Of — Send As cannot be granted for these object types.
- No application permissions are supported — this must run as a delegated (user) call.
VBAuth, developed and maintained by Andrew Richards (The IT Service Ltd) and Peter Bryant (Corylus Business Systems), © 2025–2026. All rights reserved. https://vbauth.com