Sending email prblem

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,382
Office Version
  1. 2021
Platform
  1. 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?

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'.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Could you try it this way and share the result?

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/smtpserverport") = 587
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = myemailaddress
            .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = myemailpassword
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
            .Update
        End With
        .To = myemailaddress
        .From = myemailaddress
        .Subject = "Test email"
        .TextBody = "Some text here"
        .Send
    End With
End Sub
 
Upvote 0
Thanks for your reply. It errors out at the same point with error message 'The transport failed to connect to the server.'
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top