Problems using CDO to send Email

B

Brad Pears

I have the following code in an Access 2000 project which sends an email
from my app. It works perfectly on my XP machine, runs but does not send any
mail on our Win2K term server, and crashes on our Win2K3 server...

Here is the code...

'Sending a text email
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.Sender = "(e-mail address removed)"
objMessage.To = "(e-mail address removed)"
objMessage.TextBody = "This is some sample message text."
objMessage.Send

On my XP machineit works flawlessly...

On the WIn2K term server, the code executes but no email is generated...

On the Win2K3 server, the code crashes on the .send line with the following
error...

"The SendUsing" configuration value is invalid"

Does anyone have any ideas why I am seeing three different results on three
different OS's with this code? I thought CDO was used on Win2K and up...

Thanks,

Brad
 
R

Ron Weiner

Looks Like you are NOT setting the CDOMessage.Configuration.

Here is Some Code that might help you.

Const cdoSendUsingPort = 2
Const cdoBasic = 1
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") = cdoSendUsingPort
.Item(strSch & "smtpserver") = "SMTPServer.SomeDomain.COM"
'Only used if SMTP server requires Authentication
'.Item(strSch & "SMTPAuthenticate") = cdoBasic
'.Item(strSch & "SendUserName") = "(e-mail address removed)"
'.Item(strSch & "SendPassword") = "APassword"
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.From = "Ron"
.Sender = "(e-mail address removed)"
.To = "(e-mail address removed)"
.Subject = "Sample CDO Message"
'.TextBody = "This is a test for CDO.message"
.HTMLBody = "This is not Bold But <B>This is!</B>"
.Send
End With
Set objCDOMessage = Nothing
Set objCDOConfig = Nothing

Ron W
 
B

Brad Pears

Ron, I used the code below (basically your code except I entered our smtp
server name (Exchange 2000), email names etc... but on the .send I get the
following error...

"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 this on my XP machine...

Any ideas?

Code...

Private Sub Command1_Click()
Const cdoSendUsingPort = 2
Const cdoBasic = 1
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") = cdoSendUsingPort
.Item(strSch & "smtpserver") = "true3"
'Only used if SMTP server requires Authentication
'.Item(strSch & "SMTPAuthenticate") = cdoBasic
'.Item(strSch & "SendUserName") = "(e-mail address removed)"
'.Item(strSch & "SendPassword") = "APassword"
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.From = "Brad Pears"
.Sender = "(e-mail address removed)"
.To = "(e-mail address removed)"
.Subject = "Sample CDO Message"
'.TextBody = "This is a test for CDO.message"
.HTMLBody = "This is not Bold But <B>This is!</B>"
.Send
End With
Set objCDOMessage = Nothing
Set objCDOConfig = Nothing
End Sub
 
R

Ron Weiner

Brad

If your SMTP server name is true3 and that name resolves to a valid IP
address of a SMTP server (from your development box), and there are no
firewalls that block traffic on Port 25, then I can not see any reason that
this won't work. What the error message seems to be saying is "I can't
start a communication session with your SMTP server".

The first thing I'd check would be to make sure the server accepts anonymous
connections (in today's world there are VERY few that will), or un-rem and
fill out the Authenticate, Username, and Password code.

The next thing I'd try is replacing the DNS name "true3" with the IP address
of the server.

After that I am out of Idea's Perhaps someone on the Exchange side could
shed additional light on this.

Ron W
 
B

Brad Pears

Thanks Ron...

Funny thing was that on my XP machine that simple 6 lines of code at the end
of this email worked flawlessly...

Brad
 
B

Brad Pears

Ron, should the "cdosendusing" value 25? Why is it 2? Do I not have to
communiate to the SMTP server on port 25? Or, is this something completely
different?

Thanks,

Brad
 
B

Brad Pears

Perfect, I uncommecnted the authentication code and it works... now to test
on the win2k and win2k3 servers!!!!

Brad
 
B

Brad Pears

ROn, adding in the authentication works plawlessly on my XP machine now...

However, on the Win2K and Win2K3 servers I get the following error on the
..send line

"The SMTP server name is required and was not found in the configuration
source"

I've tried replacing true3 with the IP address, full name (incl.com etc..)
all to no avail. very strange...

Any idea there?
 
R

Ron Weiner

Holy Cow I think I found the problem and it was me!

This code also worked in my environment, so I had no reason to investigate
it any further. Turns out that all of the namespaces in the CDOSYS
configuration object are case sensitive. Sheesh!!!

So you want to make ALL of those items ALL LOWER CASE. When I originally
coded it I made it all Camel Case to make it easier to read. MY FAULT!

So... You need to change

http://Schemas.microsoft.com/cdo/configuration/ To
http://schemas.microsoft.com/cdo/configuration/

and

..Item(strSch & "SMTPAuthenticate") to .Item(strSch & "smtpauthenticate")

and

..Item(strSch & "SendUserName") to .Item(strSch & "sendusername")

and

..Item(strSch & "SendPassword") to .Item(strSch & "sendpassword")

Really sorry about the bad code:-(

Ron W
 
G

Guest

Hi!

I've had the same problem for months, and posted on various groups without
any working solutions; but this helped me - Thank You!

However, my application is running in different countries with different
servers, and the users don't know which server they are using, and it may
change so I don't want to have them configure it. Is there some way I can
find out using VBA the SMTP server used in Outlook and use that? Or some
other way that means I don't have to specify it?

Brgds

Danny
 
R

Rody

I don't know if this helps, but take a look at
He may have an answer for you. Maybe he knows a way around this problem.

Rody
 
G

Guest

Hi!

Indeed, SendObject is much easier and reliable. However, it uses Outlook,
and since Outlook 2003 (I believe), it comes up with a dialog box saying that
"someone is sending emails on your behalf", waits for 5 seconds, and then you
have to click Yes to allow the mail to be sent.

This application is usually run unattended over night, so that dialog box is
unacceptable. Using CDO directly, you don't get that dialog box with the 5
second delay, so it can just send the mail and continue. (It sends error
messages to the programmer, technical setup messages to support, progress
messages to managers, and the produced reports to the users - of which there
can be up to a couple of hundred)

Brgds

Danny
 
D

DubboPete

Hi Danny

I tend to disagree... We have Groupwise as our default email, and SendObject
uses the default client, not necessarily Outlook/Express. In my case,
Groupwise kicks in when the SendObject is called...

just for reference...

DubboPete
 
G

Guest

Indeed, since Outlook is our default client, SendObject uses Outlook as I said.

Brgds

Danny
 
G

Guest

Hi!

If you search for CDO.Message in any search engine you'll find hundreds of
pages. One that I found good for code snippets was
http://www.paulsadowski.com/WSH/cdo.htm. If you're after detailed nitty
gritty about CDO itself then MSDN has for instance this page:
http://msdn.microsoft.com/library/d...s/html/_cdosys_about_cdo_for_windows_2000.asp.
BTW, the schemas page isn't supposed to be opened in a browser (if that's
what you mean by it being dead).

I've never tried sending mails from shell, so I can't help you there.

Brgds

Danny
 
R

Rhonda

I tried using CDO serval times, but get strange errors like:
"User-defined type not defined." for Dim iMsg As New CDO.Configuration.
There was somthing about a reference or Activex control. I suppose I need
more setup information and not just the lines of code.
-Automatic Send using the CDO(like with SendObject) is necessary since my
software is unattended, in a PC locked in an electrical room.
-I also Must be able to send using Hotmail(HTTP), not just POP3.
Any suggestions or links appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top