Web Hosting Forum - A Web Hosting community for Webmasters


Divi WordPress Theme

Author Topic: VBScript - Send E-Mail with CDO.Message  (Read 5393 times)

0 Members and 1 Guest are viewing this topic.

Offline Tech

  • Junior Guru
  • **
  • Posts: 183
  • iTrader: +2/-0
    • View Profile
VBScript - Send E-Mail with CDO.Message
« on: September 30, 2007, 02:29:35 PM »
Some my feel that apart from it being a nifty trick, there isn’t any real practical use for sending E-Mail from a script but lets imagine the following scenario:

You have a business critical server called "ImpServ01" that must be available at all costs. The following script can be setup to run every five minutes to check the availability of the server and email you if the server becomes unavailable. This example uses a SMTP server called "SMTP.YourDomain.com" and sends mail from "ImpServ01@YourDomain.com" to "Admin@YourDomain.com".

Option Explicit

Dim strComputer Dim colPingStatus Dim objPingStatus Dim objMessage

strComputer = "ImpSrv01"

Set colPingStatus = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_PingStatus WHERE address = '" & strComputer & "'")

For Each objPingStatus In colPingStatus

If IsNull(objPingStatus.StatusCode) or objPingStatus.StatusCode <> 0 Then

Set objMessage = CreateObject("CDO.Message")

objMessage.From = strComputer & "@YourDomain.com"

objMessage.To = "Admin@YourDomain.com"

objMessage.Subject = strComputer & " is unavailable"

objMessage.Textbody = strComputer & " is no longer accessible over the network."

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

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

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMessage.Configuration.Fields.Update

objMessage.Send

End If Next

Set colPingStatus = Nothing Set objMessage = Nothing

To attach a file to the E-Mail add the following line:

objMessage.AddAttachment "SomeDocument.doc"

Shaun Vermaak - www.ITtelligence.co.za

Article Source: http://EzineArticles.com/?expert=Shaun_Vermaak
« Last Edit: September 17, 2009, 11:49:40 AM by Kailash »

Divi WordPress Theme
Tags:
 

Related Topics

  Subject / Started by Replies Last post
0 Replies
11570 Views
Last post February 04, 2007, 01:42:44 PM
by Kailash
0 Replies
564 Views
Last post December 18, 2014, 09:04:16 AM
by happyJimmy
0 Replies
817 Views
Last post January 30, 2015, 10:23:01 AM
by Kailash
3 Replies
2715 Views
Last post March 12, 2015, 10:32:53 AM
by Kailash
4 Replies
999 Views
Last post March 20, 2015, 12:12:45 AM
by utsav