View Full Version : SendMail using CDO--what's amiss with this code?


sjl
09-04-2008, 10:20 AM
Folks,

I am attempting to send email via SMTP, not Outlook. I still can't get a simple message sent.

The message I usually get (depending on the parameters I change) is:
"The transport failed to connect to the server".


Can some of you eyeball this code and see where they may be a problem:

Dim objCDOConfig As Object, objCDOMessage As Object
Dim strSch As String

strSch = "http://schemas.microsoft.com/cdo/configuration/"
Set objCDOConfig = CreateObject("CDO.Configuration")
With objCDOConfig.Fields
.Item(strSch & "sendusing") = 2 ' Send message SMTP over the network
.Item(strSch & "smtpserver") = "smtp.nnnnn.gov"
.Item(strSch & "smtpserverport") = 25
.Item(strSch & "smtpauthenticate") = 1 'yes, authenticate
'.Item(strSch & "sendusername") = "aaa\bbbb"
'.Item(strSch & "sendpassword") = "kkkkklll"
.Item(strSch & "smtpconnectiontimeout") = 60
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.Subject = "Sample CDO Message"
.from = "wein@nnnnn.gov"
.To = "wein@nnnnn.gov"
.TextBody = "This is a test for CDO message"
.Send
End With
Set objCDOMessage = Nothing
Set objCDOConfig = Nothing
End Sub

andrey_anikin
09-04-2008, 11:00 AM
I have just done the same in my DB tonight, and was getting the same error while debugging - it was because of the wrong SSL settings I provided ( .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") was set to True while there wasn't any SSL enabled on the SMTP server). As soon as I fixed that, I started to work all right.

sjl
09-04-2008, 11:12 AM
Thanks Andrey,
I had taken that part out a while back (as I didn't see it included in others' code). I just added it back in and set it to false. However, still no go:(

I have the code in a private sub which runs when I LOAD a form. I did notice just now that when I click on the form, text appears in the lower left of the Access window saying "This recordset is not updateable". Not sure if that is related to my error message.....

Sarah

DCrake
09-05-2008, 04:00 AM
I found an email addon on the web that bypasses all the normal settings and sends it direct. Alot easier to code and there are loads of examples. It's called ASPEmail.

Try this link
http://www.aspemail.com/

andrey_anikin
09-05-2008, 04:16 AM
I had taken that part out a while back (as I didn't see it included in others' code). I just added it back in and set it to false. However, still no go:(

That depends on the SSL settings of the SMTP server you're using - if it requires SSL, you obviously need to set the option to True.

sjl
09-25-2008, 11:21 AM
I found an email addon on the web that bypasses all the normal settings and sends it direct. Alot easier to code and there are loads of examples. It's called ASPEmail.

Try this link
http://www.aspemail.com/

DCrake,
Thanks for the lead. I have not yet found any examples in VBA/Access. If you have some links, I'd be obliged.

Are you using it in Access? In my set-up here, I have Window's Scheduled Task start my db when I'm not in the office, and this triggers the emails automatically (if the week's data warrants emails). In your experience, would ASPEmail work in this type of set-up?

thanks,
sjl