README Send HTML Email #
Overview #
Sends an email with an HTML-formatted body via the Graph API POST /me/sendMail endpoint. The only difference from a plain-text send is contentType: "HTML" in the message body object — the endpoint, scope, and AppID are otherwise identical to the plain send email and attachments features. Authentication is via OAuth2 with MFA support using VBAuth.dll.
The tab provides an HTML source editor and a plain-text preview pane. Access cannot render HTML natively, so the preview strips HTML tags to give a readable approximation of the content — the actual rendered output will only be visible in the recipient’s email client.
Office apps #
- Access (tested M365)
- Excel (untested M365)
Required components #
- VBAuth.dll v1.x
- modVBAuthGlobalConstants.bas (from /shared)
- modSendEmailHTML.bas (this module)
Azure Entra App Registration #
Delegated permissions:
- Mail.Send
This AppID (20) is shared with the Email + Attachments tab. One app registration and one lclVBAuthAdmin record serve both tabs. Configure from the Email + Attachments tab — the HTML Email tab’s Configure button redirects there.
VBAuth Admin Table – Required Values #
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | 20 | Shared with Email + Attachments tab — one registration serves both |
| ActionName | VBAuth – Send Email (Attachments and HTML) | 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 | 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: modSendEmailHTML.bas #
Public functions #
Public Function SendEmailHTML( _
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=20, acquires a bearer token, and POSTs an email with contentType: "HTML". strBody must contain valid HTML — no server-side validation occurs. Exchange renders whatever HTML is provided. Returns True on HTTP 202.
Private functions #
JsonEscape(strValue)— escapes JSON special characters. Note: HTML tags (<,>,&) are NOT escaped — they are valid inside a JSON string value and must be preserved for correct rendering.BuildRecipientArray(strAddresses)— converts comma/semicolon address lists to Graph recipient array JSON.BuildSendHTMLPayload(...)— builds the complete JSON payload withcontentType: "HTML".
Preview pane behaviour #
The preview pane (txtHTMLPreview) updates automatically as HTML is typed in the source editor (txtHTMLBody). It shows a tag-stripped plain-text approximation:
- Block tags (
<br>,<p>,</p>,</tr>,</li>) are converted to line breaks before stripping - All remaining tags are removed
- Common HTML entities (
&,<,>, ,") are decoded
This is an approximation only. The actual rendered email will reflect the full HTML including styles, tables, images, and links. Use a browser or Outlook to preview complex HTML before sending.
Behaviour #
- Runs as the signed-in user (delegated permissions only).
- HTTP 202 Accepted is the success code.
Mail.Sendis the only scope required.- Authentication is interactive on first run; subsequent calls reuse the cached token.
- Exchange renders the HTML body — malformed HTML is generally tolerated but may produce unexpected layout in some clients.
Notes #
Mail.Sendis sufficient — no additional scope is required for HTML bodies.- Admin consent is required before users can authenticate.
- Inline images (using
cid:references) are not supported by this module — only HTML markup and external image URLs are rendered. - For combined HTML + attachments, the
contentTypeandattachmentsfields can coexist in the same payload. A combined module would setcontentType: "HTML"and include theattachmentsarray — both features at once. This is not implemented as a separate tab but is straightforward to add.
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