Ron's Sandbox

Email

Wednesday, 29 October 2008 11:23 by hagermanr

There is a fundamental need within SCOM to send email to individuals based on an individual alert. For instance, when you create a user account without following the proper process, an alert is generated  and an email gets sent to Winfra. Winfra has a rule in Outlook to send the email on to security. It would be much more simple to just send the email directly to security but to create a subscription, we'd have to target a management pack and alert on all the rules for the new management pack.

We now have a simple and clean method of doing this. We wrote a VBScript to accept some command line parameters and send email based on the parameters passed.

Here’s how it works. We get a list of command line parameters. The first parameter is the subject, the second parameter is the message body and any parameter after that is an email address of someone who needs to get the email.

We begin by creating a new response in the rule. We call the new response, "Send Email" and select "Run Script". We name the script SendMail.vbs and paste the  code (below) into the script window. Apply it and exit out.

Response Screen

 

Set args = WScript.Arguments

strSMTPServer = "my.relayserver.com"
strEMailSender = me@mydomain.com
strEMailSubject = args.Item(0)
strMessageBody = args.Item(1)

argCount = 2

if args.Count > 2 then
    for x = 2 to args.count - 1
        strEmailRecipient = strEmailRecipient & "; " & args.Item(x)
    next
else
    strEmailRecipient = "noreply@boeing.com"
end if

strMessageBody = Replace(strMessageBody, "\n", vbCrLf)

Set msg              = CreateObject("CDO.Message")

msg.From             = strEMailSender
msg.Subject          = strEMailSubject
msg.To                 = strEMailRecipient

' Construct Message body

msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = NTLM
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer

msg.Configuration.Fields.Update

msg.TextBody =         strMessageBody

msg.Send

Once you've done this and saved it, you next need to override your new rule. You will see in your overrides list an "Arguments" override. The format is subject body emailaddress

The email address is one or more valid email addresses separated by a space.  

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading