VBA & Macro Problems

How to Fix Excel VBA CDO SMTP Error 0x80040217

Emma BrownEmma Brown Oct 26, 2026 868 views

Question details

The user needs to resolve an SMTP transport error that occurs when sending emails via an Excel VBA macro.

How to Fix Excel VBA CDO SMTP Error 0x80040217
Product
Microsoft Excel
Device & OS
not provided
Scenario
Executing an Excel VBA macro that uses the CDO (Collaboration Data Objects) message library to send automated emails through smtp.office365.com.
Observed behavior
The VBA code fails to execute and returns transport error 0x80040217, indicating that the server rejected the sender authentication or connection.
Before you start

Ensure you have an active internet connection and verify that your Microsoft 365 account credentials (email and password) used in the VBA script are correct.

Solution 1Recommended

Verify and Update CDO Configuration Parameters

Ensure your VBA script includes the correct SMTP server, port, and SSL settings required by Microsoft 365 to establish a successful connection.

Microsoft 365 requires specific port and encryption settings for SMTP submissions. Missing or incorrect parameters in your CDO configuration schema will immediately result in authentication and transport errors.

1
Set the SMTP Server

In your VBA code, locate the configuration section and ensure the smtpserver field is strictly set to 'smtp.office365.com'.

2
Configure the Send Using Method

Set the sendusing field to '2' (which represents cdoSendUsingPort) to force the script to send via the network.

3
Update the SMTP Port

Change the smtpserverport value to '587', which is the required port for Office 365 TLS connections.

4
Enable SSL/TLS Encryption

Set the smtpusessl field to 'True' to encrypt the communication between your macro and the mail server.

5
Set Authentication Level

Set the smtpauthenticate parameter to '1' (cdoBasic) and provide your valid Microsoft 365 email and password in the sendusername and sendpassword fields.

Verify and Update CDO Configuration Parameters
CDO Schema Namespace: All configuration fields must be prefixed with the standard CDO schema namespace: 'http://schemas.microsoft.com/cdo/configuration/'.
Free Microsoft Office alternative

Discover WPS Office for Your Spreadsheet Tasks

If you are frequently running into complex configuration limitations, security restrictions, and macro errors in Microsoft 365, consider switching to WPS Office. It provides a highly compatible, lightweight, and easy-to-use spreadsheet environment for all your daily data processing needs.

Highly compatible with Microsoft Excel file formats, including .xlsx, .xlsm, and .csvLightweight installation package that runs quickly on older devicesFamiliar user interface allowing for seamless migration without a learning curveA free, cost-effective alternative to expensive Microsoft 365 subscriptions
microsoft office alternative - wps office

Frequently Asked Questions

What exactly does transport error 0x80040217 mean in Excel VBA?

Error 0x80040217 is a CDO (Collaboration Data Objects) error indicating that the SMTP server rejected the connection. This usually happens because of incorrect login credentials, incorrect port settings, or because basic SMTP authentication is blocked on the server.

Does the CDO library still work with Microsoft 365?

Yes, CDO can still send emails via Microsoft 365, provided that SMTP AUTH is explicitly enabled for the mailbox in the Microsoft 365 Admin Center and the VBA code uses the correct TLS port (587) with an App Password if 2FA is active.

Why is my correct password being rejected by smtp.office365.com in my macro?

Microsoft 365 blocks legacy basic authentication for accounts with Multi-Factor Authentication (MFA) enabled. Your regular password will be rejected in scripts. You must generate an 'App Password' from your Microsoft account settings and use that in your VBA code instead.