Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Sending email from a VB script

Hi, i used to use a VB script to test mail flow.
I used to use the below script but now I get the error message,
"Line:     7
Char:     2
Error:     ActiveX component can't create object: 'CDONTS.NewMail'
Code:     800A01AD
Source:  Microsoft VBScript runtime error

It is a new computer, XP service pack 3.
Any ideas?

thanks
StrFrom="name@domain.com"
	strto="name@domain.com"
	strbody="Email test"
	strsubject="Email test"
	
 
	Set objCDOMail = CreateObject("CDONTS.NewMail")
	objCDOMail.From = StrFrom
	objCDOMail.To = strTo
	objCDOMail.Subject = strsubject
	objCDOMail.Body = strBody
	objCDOMail.Send
	Set objCDOMail = Nothing

Open in new window

0
SteveSext
Asked:
SteveSext
  • 4
  • 2
1 Solution
 
Enigma2001Commented:
Hi,

I just use the following for sending mail. Hope it helps

set oMailMessage = CreateObject("CDO.Message")
 objMessage.Subject = "Title Here"
  objMessage.From = "From@some.address.com"
  objMessage.To = "To@some.address.com"
  objMessage.TextBody = "Message Body"
  objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Mail Server"
  objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  objMessage.Configuration.Fields.Update
  objMessage.Send
0
 
Enigma2001Commented:
sorry code error there. Replace all the objMessage to oMailMessage
0
 
SteveSextAuthor Commented:
Hi
Thanks for that..what is

objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Mail Server"

should these lines be (port 25)
objMessage.Configuration.Fields.Item = objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 25
  objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "FQDN of the hostname"

objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Mail Server"

0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
Enigma2001Commented:
The "Mail Server" is the name of your mail server
The 25 represents the port
and the other line ... is evading me at the moment.

You can declare those parts so you can just put in the 25 and server name but I only ever use it once in a script so dont bother.
0
 
Enigma2001Commented:
0
 
SteveSextAuthor Commented:
Great that worked. Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now