Avatar of leebee300
leebee300 asked on

424 Object Required

I access the following code using a button on a form in Visual Studio, on running and selecting the button I get the following error message 'Runtime error 424: Object required', has anyone any clues as to what the problem maybe ??????

Private Sub Command1_Click()
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody

sTo = "intendedrecipient@msn.com"
sFrom = "intendedrecipient@msn.com"
sSubject = "Insert here your subject text"
sTextBody = "Insert here your plain body text"

Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")

'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject = sSubject
objMail.TextBody = sTextBody

'Send the email
objMail.Send

'Clean-up mail object
Set objMail = Nothing

End Sub
Visual Basic Classic

Avatar of undefined
Last Comment
leebee300

8/22/2022 - Mon
Dirk Haest

When do you get the error ? At which line ?

An alternative to send email: a free vb dll:
www.freevbcode.com/ShowCode.Asp?ID=109
ASKER
leebee300

Hi Dhaest,

I get the error at the following line.......

Set objMail = Server.CreateObject("CDO.Message")
Dirk Haest

Try it with replacing
Set objMail = Server.CreateObject("CDO.Message")
to
Set objMail = CreateObject("CDONTS.NewMail")
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
leebee300

Dhaest,

its CDONTS I am trying to move away from as Microsoft is phasing in CDOSYS as a more powerful mail facility for future operating systems
ASKER
leebee300

sorry forgot to add, that CDONTS is not supported with service packs to 2000 and XP
p_sie

Maybe stupid question, but did you add a reference to the CDO?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
leebee300

please tell me that I have made as stupid mistake, what is the reference ??
Dirk Haest

Reference to Microsoft CDO for Windows 2000 Library
p_sie

Normally when you want to use Word or Excel or something else, you add a reference to that dll or exe through the
menu Project-->References
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
leebee300

I have done this then tried to F5 but still the same error messages is displayed
p_sie

Look at:

http://www.paulsadowski.com/WSH/cdo.htm

And at least remove the Server. before the createObject!!
ASKER
leebee300

what do you mean remove the server ??, I am not a VB`er so bare with me, I want to check it works then adapt it in to some C# code
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Dirk Haest

Set objMail = CreateObject("CDO.Message")
p_sie

I meant remove 'Server.' from server.createobject, in VB you do not use Sever.
Furthermore your code looks good:

--------------------------

Private Sub Command1_Click()
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody

sTo = "intendedrecipient@msn.com"
sFrom = "intendedrecipient@msn.com"
sSubject = "Insert here your subject text"
sTextBody = "Insert here your plain body text"

Dim objMail
'Create the mail object
Set objMail = CreateObject("CDO.Message")   'This line do not use Server.

'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject = sSubject
objMail.TextBody = sTextBody

'Send the email
objMail.Send

'Clean-up mail object
Set objMail = Nothing

End Sub
ASKER
leebee300

stressing now, did that, thankfully got no compiler error but got nothing else either after pressing the button on the form after F5'ing, I entered perfectly valid email addresses in the....

sTo = "intendedrecipient@msn.com"
sFrom = "intendedrecipient@msn.com"

.......quotes
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Dirk Haest

http://www.paulsadowski.com/WSH/cdo.htm

Do you use a remote or local server ?
ASKER
leebee300

local
ASKER
leebee300

sorry that it is only worth 30 points, its all`s I had left
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
leebee300

would using a local server affect the code used ??
dreffed

What mail server are you sending it through....

Your code does not mention it...

Read this aritcle....
http://www.developerfusion.com/show/1772/


Dreffed
ASKER
leebee300

where would my code mention it please dreffed ??

the article you sent my way has unfortunately confused me even further
Your help has saved me hundreds of hours of internet surfing.
fblack61
dreffed

Sorry about that....

I have to go ...I'll get back shortly...with your soluton.

sorry !?! :)
ASKER
leebee300

thanks very much for your help dreffed, hope to hear from you soon.
dreffed

I have just done some testing with the CDO.Message object, so scrub my last comment about the mail server.  It seems that CDO will connect using your MAPI client.
Check that you have the necessary libraries...

Under visual studio....
go project -> references

scroll through the list and look for
Microsoft CDO ....

Do you have these?

change the line...
dim objMail

to
dim objMail as object

it is always best to be explicit with variables...

I found this site useful and detailed...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/exchanchor/htms/msexchsvr_cdo121.asp


I hope this more helpful..

Dreffed
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
leebee300

did the testing you did work ok ??

I am still having no luck, do you have to add a route to the server at some point in the code, like when you are connecting to an SQL database using C# for example
ASKER CERTIFIED SOLUTION
dreffed

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
leebee300

I have moved across to C# to further develop this problem, I have finally got rid of my previous error, and I now get an error saying that the The server response was: 550 5.7.1 Unable to relay for anaddress@ontheweb.com, any ideas, sorry to waste your time if you dont use C#, I had to start using C# becasue this is the language I develop in
dreffed

C# is ok and on my list of languages....

...
That is a better message, the mailer is working, but the mailserver you are sending your mail through will not allow you to send to external email addresses.

this site has been v.helpful, and now you are in C# the code will help.
http://www.systemwebmail.com/faq/4.3.10.aspx

I find when this happens talk to the IT bod who deals with the mailserver and find out whether you can relay or whether they can allow your machine to bypass the check.

I have always used Mabry SMPTX to mail, but after your thread I am begining to like CDO.Message.

Thanks for the new idea.

Dreffed
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
leebee300

no thankyou for the help