' ********************************************************************* ' ' Name : SendSMSUsingEmail.vbs ' Author : 3Ds (UK) Limited ' Description : VBScript to send short SMS alert using (non-authenticated) ' SMTP server. ' ' Arguments : None ' ' WIZARD:PARAMS=This script requires no parameters ' WIZARD:PARAMEXAMPLE= ' ' Returns : 0 - Success ' 1 - An error occurred. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from running.||Script output also indicates "OK" for success, or "Error" with details of the faults found. ' ' Notes : Requires Windows Scripting Host (for VBScript), ' Microsoft CDO 2000 or above. ' ' Change the "TODOs" for your own requirements. ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ ' Constants Const cdoSendUsingPickup = 1 ' Send message local SMTP service pickup directory. Const cdoSendUsingPort = 2 ' Send the message using the network (SMTP over the network). Const cDefaultSMTPPort = 25 ' The port your SMTP server listens on - typically 25 ' Declare variables Dim strSMTPServer ' Our SMTP Server Dim strSMTPUser ' Our SMTP User Dim strSMTPPassword ' Our SMTP User's password Dim strSender ' The sending e-mail address Dim strRecipient ' The target e-mail address Dim strTitle ' Message title Dim strMessage ' Message text Dim objMessage ' Object reference Dim lngSMTPServerPort ' Port number ' ****************************************************************************** ' ' TODO: Change the parameters between the "<>" below for your own installation ' Also edit the title & message text as required. To check VBScript syntax ' simply run the script directly from Explorer to check for Syntax errors ' etc. when complete. ' ' ****************************************************************************** ' ------ Main Logic ------ ' Set up parameters strSMTPServer = "" lngSMTPServerPort = cDefaultSMTPPort strSender = "Sentry-go@" strRecipient = "" strTitle = "Sentry-go alert" strMessage = "Error on server <$$SERVER>. Check: <$$TEST>, Error: <$$ERROR>" ' Ensure the message is kept short - change the length if required If (Len(strMessage) > 200) Then ' Truncate it strMessage = Left (strMessage, 200) End If ' Connect to CDO for messaging logic Set objMessage = CreateObject("CDO.Message") If Err.Number <> 0 Then ' Error WScript.Echo "Error. Unable to create the CDO.Message object. " & Err.Description WScript.Quit(1) End If objMessage.From = strSender objMessage.To = strRecipient objMessage.Subject = strTitle objMessage.TextBody = strMessage ' Configure the message & transport objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = lngSMTPServerPort objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False ' Update the configuration objMessage.Configuration.Fields.Update If Err.Number <> 0 Then ' Error Set objMessage = Nothing WScript.Echo "Error. Unable to update the message configuration. " & Err.Description WScript.Quit(1) End If ' Now send the messasge objMessage.Send ' Check we managed to send If Err.Number <> 0 Then ' Error Set objMessage = Nothing WScript.Echo "Error. Unable to send the message. " & Err.Description WScript.Quit(1) End If ' ------ Cleanup ------ Set objMessage = Nothing WScript.Echo "OK. Message sent successfully" WScript.Quit (0) ' ------ End of Script ------