Hello,
$recipientList = $Context.GetParameterValue("%param-Recipients%")
This line is incorrect. The thing is that %param-Recipients% resolves into the parameter value. At the same time the $Context.GetParameterValue method accepts the name of a parameter with the param- prefix, not the value of the parameter.
$recipients += $user.Get("mail")
Specifying an array of email addresses as the first parameter of the $Context.SendMail method will not work. If you want to directly pass all the recipients, they need to be in a single string separated by commas and spaces (e.g. "jdoe@company.com, jsmith@company.com"
). As an alternative, you can directly send emails in the foreach block like in the below script.
$separator = ";" # TODO: modify me
# Email settings
$subject = "My subject" # TODO: modify me
$message = "My text" # TODO: modify me
# Get recipient DNs
$recipientDNs = $Context.GetParameterValue("param-recipients")
foreach ($dn in $recipientDNs.Split($separator))
{
# Get user email
$user = $Context.BindToObjectByDN($dn)
try
{
$userEmail = $user.Get("mail")
}
catch
{
continue
}
# Send mail
$Context.SendMail($userEmail, $subject, $message, $NULL)
}