How to Fix Excel VBA CDO SMTP Error 0x80040217
Question details
The user needs to resolve an SMTP transport error that occurs when sending emails via an Excel VBA macro.

- 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.
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.
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.
In your VBA code, locate the configuration section and ensure the smtpserver field is strictly set to 'smtp.office365.com'.
Set the sendusing field to '2' (which represents cdoSendUsingPort) to force the script to send via the network.
Change the smtpserverport value to '587', which is the required port for Office 365 TLS connections.
Set the smtpusessl field to 'True' to encrypt the communication between your macro and the mail server.
Set the smtpauthenticate parameter to '1' (cdoBasic) and provide your valid Microsoft 365 email and password in the sendusername and sendpassword fields.

Generate and Use a Microsoft 365 App Password
If your Microsoft 365 account has Two-Factor Authentication (2FA) enabled, standard passwords will trigger error 0x80040217.
Enable Authenticated SMTP in M365 Admin Center
Microsoft disables SMTP AUTH by default for new tenants, which completely blocks CDO mail submissions regardless of your VBA code.
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.

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.




