Send & Receive Issues

How to Send an HTML Email Template Using Access VBA and CDO

Bushra ParveenBushra Parveen Nov 3, 2026 869 views

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.

How to Send an HTML Email Template Using Access VBA and CDO
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

In your Microsoft Access database, press ALT + F11 to open the Visual Basic for Applications (VBA) editor.

2
Create a function to read the HTML file

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.

3
Initialize the CDO Message Object

Create your email object using Set objMessage = CreateObject("CDO.Message") and define your sender, recipient, and subject properties.

4
Assign the HTML String

Set the objMessage.HTMLBody property equal to the string variable that contains your read HTML template content.

5
Configure CDO SMTP Settings

Define the CDO.Configuration fields for the SMTP server, setting the 'sendusing' schema to 2, and specifying your 'smtpserver' and 'smtpserverport'.

6
Send the Email

Execute objMessage.Send to route the email directly through the SMTP server, bypassing Outlook completely.

Read Local HTML File into a String for CDO.Message
Reference Libraries: Depending on your setup, you may need to add a reference to 'Microsoft CDO for Windows 2000 Library' in the VBA editor (Tools > References) to access CDO constants.
Free Microsoft Office alternative

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.

Fully compatible with Microsoft Excel, Word, and PowerPoint file formats.Supports powerful macro and VBA automation in WPS Spreadsheets for advanced users.Requires significantly less system resources compared to traditional Microsoft Office installations.Features an easy-to-use, unified tabbed interface for all your document needs.
microsoft office alternative - wps office

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.