Announcement

Collapse
No announcement yet.

Script to send Emails

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to send Emails

    Hi Guys,

    I need a script to send email from my computer, while pinging a server and if there is NO ping (time out) it will send me email and 2nd option pager.
    I am using this script on my servers ou via GPO, but i want the email to be sent from MY computer not from the server.

    Code:
    Set objNetwork = CreateObject("Wscript.Network")
    strComputer = objNetwork.ComputerName 
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = strComputer & "@ENTERYOUR DOMAIN HERE(i.e. XYZ.com)"
    objEmail.To = "ENTER RECIPIENT EMAIL ADDRESS HERE"
    objEmail.Subject = "Reboot Requested" 
    objEmail.Textbody = "An admin has requested a reboot of " & strComputer & ".  Please ignore alerts, unless they last more than 15 minutes."
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ENTER MAIL SERVER NAME HERE"
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
    Thanks, Retaliator
    Thanks & Regards

    Retaliator

    MCSA/MCSE/CCNA
    Computer Science Graduate

  • #2
    Re: Script to send Emails

    Run the script on your computer.

    Here are some ways how to Ping computers using vbs;
    http://www.rlmueller.net/PingComputers.htm
    (copy the function* "PingMachine(ByVal strHost)" from Ping3.txt)
    - Usage in main script - how to call the function:
    Code:
    trComputer = "servername"
    
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & ".\root\cimv2")
    
    If Not PingMachine(strComputer) Then
      <send email **...>
    End If
    
    
    Function PingMachine(ByVal strHost)
       <*past the function from Ping3.txt here...>
    End Function
    
    ** Sending email using vbs:
    http://www.paulsadowski.com/WSH/cdo.htm


    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment

    Working...
    X