SendMail using CDO--what's amiss with this code?

sjl

Registered User.
Local time
Today, 16:46
Joined
Aug 8, 2007
Messages
221
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​
 
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
 
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/
 
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.
 
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
 

Users who are viewing this thread

Back
Top Bottom