README Send Email Draft #
Overview #
Sends an email via Microsoft Graph using a three-step pattern: create draft, optionally check its location, then send. The Graph message ID is returned after the draft is created. Authentication is via OAuth2 with MFA support using VBAuth.dll.
Use this module when you need to store or reference the message ID before sending — for audit trails, database cross-references, or linking a sent email to a record. For simple send-and-forget use modSendEmail instead.
Step 1 POSTs the message payload to /me/messages/ and returns HTTP 201 with the message ID. Step 2a (optional) GETs /me/messages/{id} to return the draft’s parent folder ID. Step 2b (optional) GETs /me/mailFolders/drafts to return the Drafts folder ID. The caller compares the two to confirm the draft is still unsent. Step 3 POSTs to /me/messages/{id}/send and returns HTTP 202. Steps 1 and 3 share one lclVBAuthAdmin row; Steps 2a and 2b each require a separate row. Steps 2a and 2b are not yet implemented in the VBAuth demo database.
Office apps #
- Access (tested M365)
- Excel (untested M365)
Required components #
- VBAuth.dll v1.x
- modVBAuthGlobalConstants.bas (from /shared)
- modSendEmail.bas (provides BuildSendMailPayload, BuildRecipientArray, JsonEscape)
- modSendEmailDraft.bas (this module)
- JSONConverter.bas (Tim Hall VBA-JSON parser)
Azure Entra App Registration #
Three rows are required in lclVBAuthAdmin. The developer chooses whether to cover them with one Entra app registration or two.
One Entra app (simpler): a single registration carries both Mail.Send and Mail.Read. All rows share the same ClientID and TenantID. The user consents to both scopes on first login.
Two Entra apps (narrower scope per registration): one registration carries Mail.Send (Steps 1 and 3); a separate registration carries Mail.Read (Steps 2a and 2b). Each registration holds only the permission it needs. The user may be prompted to authenticate twice in a session if the token cache does not cover both registrations.
Delegated permissions required across all steps:
Mail.Send— Steps 1 and 3Mail.Read— Steps 2a and 2b
VBAuth Admin Table – Required Values #
Three rows are required. Steps 1 and 3 share one row; Steps 2a and 2b each require a separate row.
Row 1 — Create Draft and Send Draft (Steps 1 and 3) #
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | (assigned by Access) | Note this value — set intAppID in the module to match |
| ActionName | VBAuth – Send Email Draft | 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 | (leave blank) | Not required for this feature |
| ScopeClaims | Mail.Send | Comma-separated Graph scopes |
| Verb | POST | HTTP method |
| URLPart1 | https://graph.microsoft.com/v1.0/me/messages/ | Note trailing slash |
| URLParameter1 | Graph message ID | Runtime value passed as strMessageID in Step 3 only |
| URLPart2 | /send | Appended after message ID in Step 3 only |
| URLParameter2 | NO VALUE REQUIRED | Not used |
| URLPart3 | NO VALUE REQUIRED | Not used |
| WaitForLogin | 60 | Seconds — NB MSXML2 timeout parameters are in milliseconds |
How the URL is built:
- Step 1:
SetEntraAPPIdValues(False, False)→ URLPart1 only →.../me/messages/ - Step 3:
SetEntraAPPIdValues(True, False, strMessageID, "")→ URLPart1 + strMessageID + URLPart2 →.../me/messages/{id}/send
Row 2 — Check Draft Location (Step 2a) #
This row is required in the developer’s own database. It is not present in the VBAuth demo database — Step 2a is not yet demonstrated there.
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | (assigned by Access) | Note this value — set intAppID in CheckDraftLocation to match |
| ActionName | VBAuth – Check Draft Location | Display name — any value acceptable |
| ClientID | (your App Client ID) | Same as Row 1 if using one Entra app; different if using two |
| TenantID | (your Tenant ID) | Same as Row 1 if using one Entra app; different if using two |
| ObjectID | (leave blank) | Not required for this feature |
| ScopeClaims | Mail.Read | |
| Verb | GET | |
| URLPart1 | https://graph.microsoft.com/v1.0/me/messages/ | Note trailing slash |
| URLParameter1 | Graph message ID | Runtime — passed as strMessageID |
| URLPart2 | ?$select=id,parentFolderId | Appended after message ID |
| URLParameter2 | NO VALUE REQUIRED | Not used |
| URLPart3 | NO VALUE REQUIRED | Not used |
| WaitForLogin | 60 | Seconds — NB MSXML2 timeout parameters are in milliseconds |
How the URL is built:
- Step 2a:
SetEntraAPPIdValues(True, False, strMessageID, "")→ URLPart1 + strMessageID + URLPart2 →.../me/messages/{id}?$select=id,parentFolderId
Row 3 — Get Drafts Folder ID (Step 2b) #
This row is required in the developer’s own database. It is not present in the VBAuth demo database — Step 2b is not yet demonstrated there.
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | (assigned by Access) | Note this value — set intAppID in GetDraftsFolderID to match |
| ActionName | VBAuth – Get Drafts Folder ID | Display name — any value acceptable |
| ClientID | (your App Client ID) | Same as Row 1 if using one Entra app; different if using two |
| TenantID | (your Tenant ID) | Same as Row 1 if using one Entra app; different if using two |
| ObjectID | (leave blank) | Not required for this feature |
| ScopeClaims | Mail.Read | |
| Verb | GET | |
| URLPart1 | https://graph.microsoft.com/v1.0/me/mailFolders/drafts | No trailing slash |
| 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 |
How the URL is built:
- Step 2b:
SetEntraAPPIdValues(False, False)→ URLPart1 only →.../me/mailFolders/drafts
Module: modSendEmailDraft.bas #
Important: intAppID #
Open the module and check the intAppID value near the top of SendEmailDraft. Update it to match the AppID Access assigned to the row you inserted in lclVBAuthAdmin.
Public functions #
Public Function SendEmailDraft( _
blnSend As Boolean, _
strPayload As String, _
ByRef strMessageID As String, _
ByRef strResult As String) As Boolean
Code language: JavaScript (javascript)
blnSend = False — Step 1. POSTs strPayload to create the draft. Returns True on HTTP 201 and populates strMessageID with the Graph message ID.
blnSend = True — Step 3. Uses strMessageID to build the send URL. Pass "" for strPayload. Returns True on HTTP 202.
strMessageID — ByRef. Populated by Step 1, consumed by Step 3. Store it in your database between the two calls if you need it for audit or reference purposes.
strResult — ByRef. Returns a brief success note or full error detail on failure.
Public Function CheckDraftLocation( _
strMessageID As String, _
ByRef strFolderID As String, _
ByRef strResult As String) As Boolean
Code language: JavaScript (javascript)
Step 2a (optional). GETs the message and returns its parentFolderId in strFolderID. Call GetDraftsFolderID to obtain the Drafts folder ID, then compare the two in the calling code to confirm the draft is still unsent. Returns True on HTTP 200. Returns False with a specific message on HTTP 404 (deleted or invalid ID).
strMessageID — the Graph message ID returned by Step 1.
strFolderID — ByRef. Receives the parentFolderId value from the Graph response.
strResult — ByRef. Returns a brief success note or full error detail on failure.
Public Function GetDraftsFolderID( _
ByRef strFolderID As String, _
ByRef strResult As String) As Boolean
Code language: JavaScript (javascript)
Step 2b (optional). GETs /me/mailFolders/drafts and returns the Drafts folder ID in strFolderID. Compare against the value returned by CheckDraftLocation to confirm the draft is still unsent. Returns True on HTTP 200.
strFolderID — ByRef. Receives the Drafts folder ID from the Graph response.
strResult — ByRef. Returns a brief success note or full error detail on failure.
Private functions #
None. Payload construction uses BuildSendMailPayload from modSendEmail.bas.
Behaviour #
- Runs as the signed-in user (delegated permissions only).
- Step 1 returns HTTP 201 with the full draft message object. Only the message ID is extracted — the caller can extend the module to parse additional fields if needed.
- Step 2a returns HTTP 200 with the message object filtered to
idandparentFolderId. Step 2b returns HTTP 200 with the Drafts folder object. The caller comparesparentFolderIdfrom Step 2a against the folderidfrom Step 2b to confirm the draft is still unsent. - Step 3 returns HTTP 202 with no response body. HTTP 202 confirms Graph has accepted the message for delivery — it does not guarantee delivery. Exchange transport rules or spam filtering may subsequently drop it. If emails go missing, check the sender’s Sent Items folder and ask your Exchange administrator to check transport logs.
- Authentication is interactive on first run; subsequent calls within the session reuse the cached token. If Steps 1 and 3 share one Entra app and Steps 2a and 2b use a different registration, the user may be prompted a second time for Steps 2a and 2b.
Notes #
modSendEmail.basmust be present in the project asBuildSendMailPayloadis defined there.- The message ID returned by Step 1 is the Graph message ID, not an Exchange or SMTP message ID. It is valid for subsequent Graph calls to the
/me/messages/{id}endpoint. - For simple send-and-forget without needing the message ID, use
modSendEmail.basinstead — it is a single call with less overhead.
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