CDO and sending e-mail
I am trying to use CDO to send e-mail.
I am using the following code:
Set email = CreateObject("cdo.message")
With email
.To = "someone@domain.com"
.Subject = "something"
.From = "someone@domain.com"
.Send
End With
I get the following error message when I run the code:
The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available.
I am running Outlook 2000 on Windows XP.
I tried an alernative way of sending e-mail, but I can't seem to find a way to have the "From" field option with the follwing code that does work:
Set olOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
' Outlook not running - start it
Set olOutlookApp = CreateObject("Outlook.Application")
blnNewOutlookApp = True
End If
' Create E-mail
Set olEMail = olOutlookApp.CreateItem(olMailItem)
With olEMail
.To = "someone@domain.com"
.Subject = "Test Message"
.Body = "Test
.Send
End With
Any suggestions on why the CDO code gives the above error message, and if there is a way to have the "From" field option using the CreateObject("Outlook.Application")? The main thing is that I need to have the ability to change the "From" field.
Thank you.
[1373 byte] By [
mike3434] at [2007-11-11 8:47:28]

# 1 Re: CDO and sending e-mail
I looked at some code that uses CDO to send email and I noticed that
it had code to set up Confiuration.Fields for the CDO.Message.
Here is the code.
Dim x as CDO.Message
Set x = New CDE.Message
x.Configuration.Fields(cdoSmtpServer) = "mail.someplace.com"
x.Configuration.Fields(cdoSendUsingMethod) = cdoSendUsingPort
x.Configuration.Fields(cdoSTMPServerPort) - 25
x.Configuration.Fields.Update
x.To = Text1.Text
x.From = "User@someplace.com"""
x.Subject = "A cdo message"
x.TextBody = "Hi"
x.Send
Set x = Nothing
I didn't see the Configuration.Fields being set up in your code, so see
if this helps.
# 2 Re: CDO and sending e-mail
This is what works for me and my project is referencing CDO 1.21 . . .
Private Sub SendEmail(sSubject As String, _
sBody As String, _
sRecipientName As String, _
sRecipientEmail As String)
Dim cdoMail As Object
Set cdoMail = CreateObject("CDO.Message")
cdoMail.To = "" & sRecipientName & "" & "<" & sRecipientEmail & ">"
If sHOSTTYPE = "TEST" Then
cdoMail.From = """JOBQ2""<jobq2@mycompany.com>"
Else
cdoMail.From = """JOBQ1""<jobq1@mycompany.com>"
End If
cdoMail.Subject = sSubject
cdoMail.TextBody = sBody
cdoMail.Send
Set cdoMail = Nothing
End Sub