Home   Help Login Register  
Welcome, Guest. Please login or register.

Login with username, password and session length

Search
Free Website WooThemes - Quality Themes, Great Support
Pages: [1]   Go Down
Print
Topic: VBScript - Send E-Mail with CDO.Message  (Read 1928 times)
« on: September 30, 2007, 01:59:35 AM »
Tech Offline
Newbie

View Profile
*

iTrader: 1
Posts: 183



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

Share this topic on AskShare this topic on BlinkbitsShare this topic on BlinklistShare this topic on BloglinesShare this topic on BmarksShare this topic on Del.icio.usShare this topic on DiggShare this topic on DzoneShare this topic on FacebookShare this topic on Feed Me LinksShare this topic on FurlShare this topic on GoogleShare this topic on LiveShare this topic on MagnoliaShare this topic on MySpaceShare this topic on NetvouzShare this topic on NewsvineShare this topic on OneviewShare this topic on RedditShare this topic on RojoShare this topic on ScuttleShare this topic on ShadowsShare this topic on SlashdotShare this topic on SpurlShare this topic on SquidooShare this topic on StumbleUponShare this topic on TechnoratiShare this topic on TwitterShare this topic on TipdShare this topic on YahooShare this topic on Google buzz
« Last Edit: September 16, 2009, 11:19:40 PM by Kailash » Logged

Pages: [1]   Go Up
Print
Jump to:  

Untitled Document
(c) 2010 HELM, WHM, cPanel, ASP, .Net development, PHP, MySQL, MSSQL Server, SEO support forum
Powered by SMF 1.1.16 | SMF © 2011, Simple Machines | Forum style designed by PixelSlot
Web Hosting - Sitemap - XML Sitemap