pcc
Well-known Member
- Joined
- Jan 21, 2003
- Messages
- 1,382
- Office Version
- 2021
- Platform
- Windows
I have the following code that I had been using successfully in the past. However, it no longer works. I am not sure if Outlook settings have changed or not, or if it's because I have upgraded my laptop, Windows version, and Excel version. (I'm now on Windows 11 and Excel 2021). Note that the variables 'myemailaddress' and 'myemailpassword' are declared as public variables elsewhere in the module, not included here for obvious reasons! Can anyone please advise what setting I should use?
It errors out at the '.Send' statement with error message 'The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available'.
VBA Code:
Sub sendmail()
With CreateObject("CDO.message")
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp-mail.outlook.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = myemailaddress
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = myemailpassword
.Update
End With
.to = myemailaddress
.From = myemailaddress
.Subject = "Test email"
.TextBody = "Some text here"
.Send
End With
End Sub
It errors out at the '.Send' statement with error message 'The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available'.