README Send Email Without Attachments #
What this does #
Sends an email as the authenticated user via the Microsoft Graph /me/sendMail endpoint, using OAuth2 with MFA. Supports To, CC, and BCC address lists (comma- or semicolon-separated), plain text or HTML body, and the option to save a copy to Sent Items.
Note: Before sending, you may wish to check your recipient addresses against the user’s personal Exchange contacts folder. See the Validate Contacts module for that capability.
Office apps #
- Access (tested M365)
- Excel (untested M365)
Required components #
- VBAuth.dll v1.x
- modVBAuthGlobalConstants.bas (from /shared)
- modSendEmail.bas (this module)
Azure Entra App Registration #
Delegated permissions:
- Mail.Send
VBAuth Admin Table – Required Values #
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | 4 | Identifies this feature’s configuration record |
| ActionName | VBAuth – Send Email | 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 — shared registration with Validate Contacts (AppID=3) |
| ScopeClaims | Mail.Send,Contacts.Read | Comma-separated Graph scopes — shared registration with Validate Contacts (AppID=3) |
| 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: modSendEmail.bas #
Design note: This module separates payload construction from sending into two public functions. This is intentional — the
sendMailJSON payload can be complex, soBuildSendMailPayloadis exposed publicly to allow callers to inspect, log, or modify the payload before sending. The typical calling pattern is: callBuildSendMailPayloadfirst, then pass the result directly toSendEmail.
Public functions #
SendEmail(strPayload As String, ByRef strResult As String) As Boolean
Code language: JavaScript (javascript)
Acquires a bearer token for the configured AppID, then POSTs the supplied JSON payload to the Graph /me/sendMail endpoint. Returns True on HTTP 202 (accepted). Returns False on any other HTTP status or error, with strResult containing the error detail.
BuildSendMailPayload(strTo, strCC, strBCC, strSubject, strBody, blnBodyHTML, blnSaveToSentItems) As String
Code language: JavaScript (javascript)
Constructs the JSON request body from the supplied field values. strTo, strCC, and strBCC are comma- or semicolon-separated address lists. blnBodyHTML sets the body content type to HTML if True, plain text if False. blnSaveToSentItems controls whether a copy is saved to the user’s Sent Items folder. Returns the complete JSON string ready to pass to SendEmail.
Typical calling pattern #
Dim strPayload As String
Dim strResult As String
strPayload = BuildSendMailPayload(strTo, strCC, strBCC, strSubject, strBody, False, True)
If SendEmail(strPayload, strResult) Then
MsgBox "Sent.", vbInformation
Else
MsgBox "Failed: " & strResult, vbCritical
End If
Code language: PHP (php)
Behaviour #
- Sends email as the authenticated (signed-in) user — not as a service account
- Graph returns HTTP 202 on success with no response body
- A network timeout returns a descriptive error message — timeout duration is controlled by
lngHTTPTimeoutinmodVBAuthGlobalConstants.bas - Special characters in subject and body (backslash, double-quote, CR/LF, tab) are escaped automatically by
JsonEscapebefore the payload is built - Requires interactive sign-in — application permissions are not supported
Notes #
- Does not support application permissions
- CC and BCC are optional — pass an empty string for any field not required
- The Graph API does not provide delivery confirmation — HTTP 202 means the message was accepted for delivery, not that it was delivered
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