I had been using CDO object with Windows XP for a while and the code always ran without a problem, as long as the SMPT server was installed and properly set up. That was easy to do. As I moved the code to Windows Vista, I come to realize that my code no longer worked. I tried installing the SMTP Server on Windows Vista, but that was pointless since it is no longer available. I was having some trouble believing it was not there given that I used Windows Vista Ultimate, but fellow MVPs Bernard Cheah (http://www.iis.net/ http://msmvps.com/blogs/bernard/) and Gary VanderMolen confirmed my worries. Ron de Bruin, a fellow Excel MVP, also took part in the conversation about the issue. He also has an article on the subject which can be found here: http://www.rondebruin.nl/cdo.htm
According to Gary, this is pretty much useless anyway given that most ISPs nowadays block all port 25 traffic except to their own SMTP server.
In that case, I had to adapt things slightly so that I could route my emails through my SMTP Server. Nonetheless, I can still use Vista to route the email to a local pickup folder so that I can at least test things.
Here’s how it is done (uncomment the code to test locally):
Dim oCDO As Object
Dim oCDOConfig As Object
Const c_sUsername As String = "Your_Username_Goes_Here"
Const c_sPassword As String = "Your_Passoword_Goes_Here"
' if you are using localhost to route the e-mail, you need to define
' a pickup folder. In this case, I use: "C:\inetpub\mailroot\Pickup"
Const c_sPickupFolder As String = "C:\inetpub\mailroot\Pickup"
Const c_iSMPTPort As Integer = 25
Dim iSendUsing As Integer
Dim sSMPTServerName As String
iSendUsing = 2 'remote host
' iSendUsing = 1 'localhost
' Define the SMTP Server here. "localhost" for using Vista's localhost
' as the server. In the case below, you should use your own server.
' sSMPTServerName = "localhost"
sSMPTServerName = "Your_SMTP_server_goes_here" 'e.g.: smtp.youcompanyname.com
Set oCDO = CreateObject("CDO.Message")
Set oCDOConfig = CreateObject("CDO.Configuration")
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = iSendUsing
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMPTServerName
.Item("http://schemas.microsoft.com/cdo/configuration/username") = c_sUsername
.Item("http://schemas.microsoft.com/cdo/configuration/password") = c_sPassword
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = c_iSMPTPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = c_sPickupFolder
Set .Configuration = oCDOConfig
.From = Sender@Email.com
.To = Receiver@Email.com
.Subject = "Test Message"
Set oCDOConfig = Nothing
Set oCDO = Nothing