VB script to email performance alerts

I set up a performance alert in Windows 2003 SP1 to monitor logical drive space. I'm looking for a way to have the alert when triggered to email me. I did a quick google search and found this site - http://www.windowsitpro.com/Articles/ArticleID/24594/24594.html?Ad=1.

I downloaded the code, changed the values it describes in the article and tried to run it with no success. I get "Unexpected XML declaration - declaration must be at the beginning of the file".
So i remove the first line so it's now <?xml version="1.0"?>. now i get this error " The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available."

here is the full code, maybe someone can tell me if there is an obvious error in the code. I don't know VB at all.

<?xml version="1.0"?>

<job id="SendAlert">
<reference object="CDO.Message"/>
<script language="VBScript">

<![CDATA[
Option Explicit

Dim objArgs, strMsgBody, iMsg, iConf, Flds

Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
   strMsgBody = objArgs(0)
End If

Set iMsg = CreateObject("CDO.Message")
Set iConf = iMsg.Configuration
Set Flds = iConf.Fields


Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "10.10.1.4"
Flds(cdoSMTPServerPort) = 25
Flds(cdoSMTPConnectionTimeout) = 10
Flds(cdoSMTPAuthenticate) = cdoBasic
Flds(cdoSendUserName) = ""
Flds(cdoSendPassword) = ""
Flds.Update

With iMsg
  Set .Configuration = iConf
      .To = "admin@domain.com"
      .From = "alert@domain.com"
      .Subject = "Windows 2000 Performance Alert"
      .TextBody = strMsgBody
      .Send
End With

WScript.Echo "Send mail completed."
WScript.Quit(0)
]]>
</script>
</job>
LVL 1
js479Asked:
Who is Participating?
 
JohnDemerjianConnect With a Mentor Commented:
i think this script is self explanatory.  call it "email_me.vbs" and run it from a command prompt or in a batch file with the command  

cscript email_me.vbs

good luck
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "This is the subject of the email" 
objMessage.Sender = "your_name@company.com" 
objMessage.To = "john_jones@company.com, joe.smith@company.com"
objMessage.TextBody = "The network is down, but I'm feeling better."
 
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
 
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.company.com"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
 
objMessage.Configuration.Fields.Update
 
'==End remote SMTP server configuration section==
 
objMessage.Send

Open in new window

0
 
ExTxCxCommented:
I have been using the following function for some time now without issue.
Function sendMail()
	Dim objMessage
	'WScript.Echo logPath & "\backup" & strDate & ".html"
	Set objMessage = CreateObject("CDO.Message")
	objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'use '1' for local SMTP
	objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmtpServer
	objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = strSmtpPort
	If strSmtpAuth = "yes" Then
		objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'use '2' for NTLM authentication
		objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strSmtpUser
		objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strSmtpPass
	End If
	If strSmtpSsl = "yes" Then
		objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
	End If
	objMessage.Configuration.Fields.Update
	objMessage.Subject = "FUSD Backup Report for " & strDate & "."
	objMessage.From = strSendingEmail
	objMessage.To = strReportEmail
	objMessage.HTMLBody = IE.Document.Body.InnerHTML
	'objMessage.AddAttachment = logPath & "\backup" & strDate & ".html"
	objMessage.Send
End Function

Open in new window

0
 
js479Author Commented:
You'll have to forgive me, i don't know programming at all. Should I copy that code into a note pad and name it .wsf like I did with my original script?
And where would I enter the SMTP address and email fields?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
js479Author Commented:
How can I troubleshot this?
I ran it, got no errors but also got no email.
0
 
ExTxCxCommented:
Check that you don't have a spam filter that is catching these.  I have, in most cases, had to add the sending address to a whitelist in order for spam filters not to hit on them.  Make sure that the ip address of your machine is allowed to relay through the smtp server.
0
 
JohnDemerjianCommented:
I have also run into the need to add the ip of the machine trying to send the email to the relay list of the smtp server.  
0
 
js479Author Commented:
Alright - I messed up. I forgot to add the last line of the code you showed me JohnDemerjian.

So I just copied it in and now I get an error.
*****************************************
Windows Script Host
Script:     C:\emailme2.vbs
Line:     25
Char:     1
Error:     The transport failed to connect to the server.

Code:     80040213
Source:     CDO.Message.1
*****************************************



Line 25 is the last line "objMessage.Send"
0
 
js479Author Commented:
Nevermind - monday morning stupidity. It's working - thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.