Solved

Sending email from a VB script

Posted on 2009-04-13
6
265 Views
Last Modified: 2012-05-06
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
Comment
Question by:SteveSext
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:Enigma2001
ID: 24134655
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
 
LVL 4

Expert Comment

by:Enigma2001
ID: 24134660
sorry code error there. Replace all the objMessage to oMailMessage
0
 

Author Comment

by:SteveSext
ID: 24134711
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 4

Expert Comment

by:Enigma2001
ID: 24134726
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
 
LVL 4

Accepted Solution

by:
Enigma2001 earned 500 total points
ID: 24134729
0
 

Author Closing Comment

by:SteveSext
ID: 31569766
Great that worked. Thanks
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Find out what you should include to make the best professional email signature for your organization.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question