How to Send an HTML Email Template Using Access VBA and CDO
Question details
The user needs to send an email using a local HTML template via an SMTP server using Microsoft Access VBA and CDO, specifically without relying on Microsoft Outlook.

- Product
- Microsoft Access for Microsoft 365
- Device & OS
- Windows (64-bit)
- Scenario
- Distributing an Access database to employees who may not have MS Outlook installed, requiring the application to send automated HTML emails directly through an SMTP server.
- Observed behavior
- The CDO.Message.HTMLBody property fails or does not render correctly when provided with a local file path, because it strictly requires the actual HTML string content.
Verify your SMTP server credentials (server address, port, and authentication details) and note the exact local file path of your HTML template before writing your VBA script.
Read Local HTML File into a String for CDO.Message
Use VBA's FileSystemObject or Open statement to read the contents of the local HTML file into a string variable, and then assign that string to the CDO.Message HTMLBody property.
The CDO (Collaboration Data Objects) library expects raw HTML code for the HTMLBody property, not a file path. By programmatically opening the file and reading its contents into memory, you can successfully pass the template to the email body without invoking Microsoft Outlook.
In your Microsoft Access database, press ALT + F11 to open the Visual Basic for Applications (VBA) editor.
Use the 'Scripting.FileSystemObject' to open your local HTML file and read it. For example: Set fso = CreateObject("Scripting.FileSystemObject"), then use fso.OpenTextFile(YourFilePath, 1).ReadAll to store the HTML into a string variable.
Create your email object using Set objMessage = CreateObject("CDO.Message") and define your sender, recipient, and subject properties.
Set the objMessage.HTMLBody property equal to the string variable that contains your read HTML template content.
Define the CDO.Configuration fields for the SMTP server, setting the 'sendusing' schema to 2, and specifying your 'smtpserver' and 'smtpserverport'.
Execute objMessage.Send to route the email directly through the SMTP server, bypassing Outlook completely.

Switch to WPS Office for Lightweight Automation
If your team struggles with missing Microsoft Outlook installations or the heavy bloat of Microsoft 365, consider transitioning your document and spreadsheet workflows to WPS Office. It provides robust capabilities in a lightweight package without forcing users into a restrictive ecosystem.

Frequently Asked Questions
Why does CDO HTMLBody ignore my local file path?
The HTMLBody property is strictly designed to process raw HTML markup strings. If you provide a file path, CDO treats the path text itself as the email body rather than retrieving the file's contents. You must read the file programmatically first.
Does CDO require Microsoft Outlook to be installed?
No. Collaboration Data Objects (CDO) can connect directly to an external SMTP server. This allows you to send emails from your Access database even on computers where Microsoft Outlook is unavailable or not configured.
How do I embed images into a CDO HTML template?
You can host the images externally and use absolute URLs (e.g., <img src="http...">) inside your HTML. Alternatively, you can use the AddRelatedBodyPart method in CDO to embed local image files directly into the email payload.
What port should I use for my SMTP server in CDO?
The port depends on your email provider's settings. Standard unencrypted SMTP uses port 25, while secure connections typically use port 465 (SSL) or 587 (TLS). You must also set the 'smtpusessl' configuration field to True if a secure port is used.




