Workflow Scripting Emails

So I'm very new to ARS, I need the ability to Send an email after an attribute of a user is modified. The Email address I need to send to is stored as a Virtual Attribute on the object being modified. additional to build and Write the email I would be reading additional attributes from the Modified Object, But I have ran into a road block. 

function onPostModify($Request)
{

     Send-MailMessage -from 'ADMIN@MyDomain.com' -To 'ME@mydomain.com' -subject "hello world" -body "This is a test" -usessl -SmtpServer 'smtp.mydomain.com' -Port '587

}

using PowerShell attempting to send Email The way I'm familiar with doesn't appear to work. Is there a different Method/cmdlet I should be using to send an email VIA an ARS script?

  • Hello,

    The function that you have defined should indeed send an e-mail message (notwithstanding the missing single quote at the end of the line; guessing that's a typo in posting the message?).

    Since you're using onPostModify, I'll assume that you're implementing this as a policy and not a workflow. Is the policy that implements this script applied to some kind of container (OU, Managed Unit, etc)? Are there any error messages recorded to the Active Roles event log around the time that you modified an some object affected by said policy? When you run this script manually to test, have you run it from the Active Roles server itself? E.g., is the SMTP server accepting traffic from the AR server/IP?

    In this particular case, I would probably suggest that you use a workflow instead of a policy. You'll still need to have your script since the recipient is defined by an attribute of the object, but workflows are generally easier to manage.

    Cheers,
    Shawn

  • yes the missing single quote only exist in the re typing. I am able to successfully run that command from the ARS Server and receive mail and no errors that I could find.

    The Script is part of a Workflow

    The Workflow is triggered when an Attribute Employee Status is modified.

    If the Value of the attribute meets a certain criteria 

    The Account gets Expired. which is happening in testing

    but after the Account is Expired I have the workflow run a script. notifying the supervisor of the employee.

    I was assuming I wanted a policy script that used  "onPostModify"   since it was occurring after the attribute was changed. 

  • Hi, srsparks!

    The name of the function, when you use a workflow, is completely arbitrary since you tell the workflow what function to run:

    Sounds like you'll need to have a look at that event log to see if anything is being reported there. That, and you may need to insert some debugging info into your script to make sure the input values are what you expect them to be.

    On a related note, here is a function I wrote to extract SMTP mail configuration from the mail configuration object in Active Roles that may be useful to someone.

    Cheers!
    Shawn

    function Get-MailConfiguration() {
      param(
        $mailConfigurationDN = "CN=Default Mail Settings,CN=Mail Configuration,CN=Server Configuration,CN=Configuration"
      )
    
      $mailConfiguration = [adsi]("EDMS://$mailConfigurationDN")
      [void]$mailConfiguration.RefreshCache("edsaRuleDefinition")
      $mailConfigurationXml = [xml]$mailConfiguration.Properties["edsaRuleDefinition"].Value
      $xmlNS = New-Object -TypeName System.Xml.XmlNamespaceManager($mailConfigurationXml.NameTable)
      [void]$xmlNS.AddNamespace('AR','urn:schemas-quest-com:ActiveRolesServer:Mail')
      $smtpConfig = @{senderAddress=($mailConfigurationXml.SelectSingleNode('/AR:MailConfiguration/AR:From/@address',$xmlNS).'#text')}
      [void]$smtpConfig.Add("hostName",($mailConfigurationXml.SelectSingleNode('/AR:MailConfiguration/AR:Server/@host',$xmlNS).'#text'))
      [void]$smtpConfig.Add("port",($mailConfigurationXml.SelectSingleNode('/AR:MailConfiguration/AR:Server/@port',$xmlNS).'#text'))
      [void]$smtpConfig.Add("senderDisplayName",($mailConfigurationXml.SelectSingleNode('/AR:MailConfiguration/AR:From',$xmlNS).'#text'))
      return $smtpConfig
    }