Solved

Sending email from a VB script

Posted on 2009-04-13
6
263 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
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

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
how to add IIS SMTP to handle application/Scanner relays into office 365.

809 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