0 votes

I have been asked to automate an email that sends to people who is having a birthday or an anniversary but from addresses need to be able to be changed based on the office they are in. I can make a scheduled task run based on the office location. I have two date custom attributes adm-CustomAttibuteDate4, adm-CustomAttibuteDate5. I could use the same script and just change the body of the email.

by (1.3k points)
0

Hello,

Could you be more specific about addresses of the email notifications recipients? Do we understand correctly that the email addresses depend on the Office property value of the user having a birthday/anniversary? Do you need to send the notifications on the day specified in the attribute (CustomAttibuteDate4 or CustomAttibuteDate5) or a number of days in advance?

0

The recipients will use their email address. But based on the recipient's office the sending address will be different. if the script includes a from address variable that can be filled in I can make different tasks. I need the email to send on the birthday and anniversary day. So if a user was born on 11/02/1982 I need that email to send on 11/02 of every year.

I think i forgot to mention I need the email to send in HTML so I can include a picture.

0

Hello,

The recipients will use their email address. But based on the recipient's office the sending address will be different.

Sorry for the confusion, but it is not quite clear how the email addresses of recipients should be obtained. Do you need to send the notifications to the email address stored in the Email property of the user that is having a birthday or anniversary? If so, how does that depend on the Office property value? A live example of the desired workflow would be very helpful.

0

The email addresses of recipients should be obtained from the email properties. But the from address needs to be changeable.

The following is from a different automated email we run

$toAddress = "%mail%"
$fromAddress="kgarcia@test.com"

We need to be able to change the from address. If we can do that I can add conditions to run different versions of the script.

0

Hello,

What exactly do you mean by changeable from address? Do you need to set a mapping for the recipient Office property value and the From addresses? For example:
if Office equals London, the From address is london@test.com,
if Office equals New York, the From address is newyork@test.com,
if Office equals Sydney, the From address is sydney@test.com.

If that is not it, please, provide us with a live example of the way you need the solution to work.

0

if Office equals London, the From address is Bill@test.com,
if Office equals New York, the From address is Jim@test.com,
if Office equals Sydney, the From address is Bob@test.com

I don't know what you mean by a live example.

We just need to be able to change the from address in the script I can do conditions when setting up the Scheduled task mainly because we have over 55 offices and add more all the time but only have like 6-8 people the email need to set as the from address

0

Hello,

Thank you for clarifying. Could you specify what version of Adaxes you are using? To check that:

  1. Launch Adaxes Administration Console.
  2. Right-click your service.
  3. Click Properties in the context menu.
  4. Adaxes version is displayed on the General tab.
0

2017.2
3.8.14823.0

1 Answer

0 votes
by (270k points)
selected by
Best answer

Hello,

Thank you for clarifying. You will need to create a Scheduled Task that will execute the below PowerShell script. To create the task:

  1. Launch Adaxes Administration Console.

  2. Right-click your Adaxes service node, navigate to New and click Scheduled Task.

  3. On step 3 of the Create Scheduled Task wizard select User Object type and click Next.

  4. Click Add Action.

  5. Select Run a program or Powershell script.

  6. Enter a short description and paste the below script into the Script field. In the script:

    • $to - specifies the recipient email address;
    • $smtpServer - specifies the SMTP server to use when sending a notification
    • $subject - specifies the email notification subject;
    • $fromInfo - matches the email addresses that can be used in the From field with Office property values;
    • $imageUrl - specifies the URL of the picture to be included into the notification;
    • $htmlMessage - specifies the email message template.
     $to = "%mail%" # TODO: modify me
     $smtpServer = "mail.domain.com" # TODO: modify me
     $subject = "My Subject" # TODO: modify me
     $fromInfo = @{
         "recipient1@domain.com" = @("Office1", "Office2")
         "recipient2@domain.com" = @("Office3")
     } # TODO: modify me
     $imageUrl = "https://mysite.com/gallery/Image.png" # TODO: modify me
     $htmlMessage = "<b>My Text</b><br/><b>Image:</b> <img src=$imageUrl>" # TODO: modify me
    
     # Get e-mail address of user
     try
     {
         $office = $Context.TargetObject.Get("physicalDeliveryOfficeName")
     }
     catch
     {
         $Context.LogMessage("Office property is not specified for user %fullname%.", "Warning")
         return
     }
    
     # Get the From address
     $from = $NULL
     foreach ($emailAddress in $fromInfo.Keys)
     {
         if ($fromInfo[$emailAddress] -notcontains $office)
         {
             continue
         }
         $from = $emailAddress
     }
    
     if ($from -eq $NULL)
     {
         $Context.LogMessage("The email address for the '$office' office is not specified", "Warning")
         return
     }
    
     # Send mail
     Send-MailMessage -To $to -From $from -SmtpServer $smtpServer -Body $htmlMessage -BodyAsHtml -Subject $subject

  7. Click OK.

  8. Click Next and finish creating the Scheduled Task.

0

Where does the script look for when to send? I need the email to send on the birthday and anniversary day. So if a user was born on 11/02/1982 I need that email to send on 11/02 of every year.

0

Hello,

Sorry for the confusion, this part was missed in the previous post. Here are the updated instructions:

  1. Launch Adaxes Administration Console.

  2. Right-click your Adaxes service node, navigate to New and click Scheduled Task.

  3. On step 3 of the Create Scheduled Task wizard select User Object type and click Next.

  4. Click Add Action.

  5. Select Run a program or Powershell script.

  6. Enter a short description and paste the below script into the Script field. In the script:

    • $to - specifies the recipient email address;
    • $smtpServer - specifies the SMTP server to use when sending a notification
    • $subject - specifies the email notification subject;
    • $fromInfo - matches the email addresses that can be used in the From field with Office property values;
    • $imageUrl - specifies the URL of the picture to be included into the notification;
    • $htmlMessage - specifies the email message template.
     $to = "%mail%" # TODO: modify me
     $smtpServer = "mail.domain.com" # TODO: modify me
     $subject = "My Subject" # TODO: modify me
     $fromInfo = @{
         "recipient1@domain.com" = @("Office1", "Office2")
         "recipient2@domain.com" = @("Office3")
     } # TODO: modify me
     $imageUrl = "https://mysite.com/gallery/Image.png" # TODO: modify me
     $htmlMessage = "<b>My Text</b><br/><b>Image:</b> <img src=$imageUrl>" # TODO: modify me
    
     # Get e-mail address of user
     try
     {
         $office = $Context.TargetObject.Get("physicalDeliveryOfficeName")
     }
     catch
     {
         $Context.LogMessage("Office property is not specified for user %fullname%.", "Warning")
         return
     }
    
     # Get the From address
     $from = $NULL
     foreach ($emailAddress in $fromInfo.Keys)
     {
         if ($fromInfo[$emailAddress] -notcontains $office)
         {
             continue
         }
         $from = $emailAddress
     }
    
     if ($from -eq $NULL)
     {
         $Context.LogMessage("The email address for the '$office' office is not specified", "Warning")
         return
     }
    
     # Send mail
     Send-MailMessage -To $to -From $from -SmtpServer $smtpServer -Body $htmlMessage -BodyAsHtml -Subject $subject

  7. Click OK.

  8. Double-click Always.

  9. Select If <property><relation><value>.

  10. Select If CustomAttributeDate4 less or equal and click Edit.

  11. Select plus 1 day and click OK twice.

  12. Right-click the condition you created and click Add New Condition.

  13. Select If <property><relation><value>.

  14. Select If CustomAttributeDate4 greater or equal and click Edit.

  15. Select minus 1 day and click OK twice.

  16. Right-click the set of actions and conditions you have created (not a separate action or condition) and click Copy.

  17. Press Ctrl+V.

  18. In both conditions of the new set, change CustomAttributeDate4 to CustomAttributeDate5.

  19. In the new set, update the script (e.g. message template and subject) and script description.

  20. Click Next and finish creating the Scheduled Task.Finally, you will have something like the following:

0

I just tested it and didn't seam to work. I'm not sure how it will when the date is as follows. 11/5/1982. Is there another field type I should be using that doesn't have they birth year?

0

Hello,

You will need to use the If PowerShell script returns true condition instead of two If <property><relation><value> conditions in each set of actions and conditions. Finally, your Scheduled Task will look like the following:

In the condition, use the below script. In the script, the $attributeName variable specifies LDAP name of the custom attribute storing the birth date or the anniversary date (i.e. adm-CustomAttributeDate4 and adm-CustomAttributeDate5 in your case).

$attributeName = "adm-CustomAttributeDate4"

try
{
    $date = $Context.TargetObject.Get($attributeName)
}
catch
{
    return
}

$currentDate = [System.Datetime]::UtcNow
$Context.ConditionIsMet = $date.Month -eq $currentDate.Month -and $date.Day -eq $currentDate.Day
0

So we just went live this is code and it is sending the anniversary emails to users on their 1st day. I tried the following

but it still sent. I'm not sure if I did the conditions wrong or maybe there is something that needs to be updated with the script.

Script i'm using:

$attributeName = "adm-CustomAttributeDate3"

try
{
$date = $Context.TargetObject.Get($attributeName)
}
catch
{
return
}

$currentDate = [System.Datetime]::UtcNow
$Context.ConditionIsMet = $date.Month -eq $currentDate.Month -and $date.Day -eq $currentDate.Day

0

Hello,

As we understand, you store the hire dates in the CustomAttributeDate3 attribute. The notifications are sent because the month and day in the attribute are the same as the current ones. To remedy the issue, you need to add a comparison that will make sure that years in the dates are not equal. Find the updated script below.

$attributeName = "adm-CustomAttributeDate3"

try
{
    $hireDate = $Context.TargetObject.Get($attributeName)
}
catch
{
    return
}

$currentDate = [System.Datetime]::UtcNow
$Context.ConditionIsMet = $hireDate.Year -ne $currentDate.Year -and $hireDate.Month -eq $currentDate.Month -and $hireDate.Day -eq $currentDate.Day

Related questions

0 votes
1 answer

Is is possiable to send Automate an email to go out to the users of a delegated mailbox? We give Full Access and Send As access of disabled accounts to thier replacements for 30days ... then send a email to each one of them? Adaxes version: 2017.2 3.8.14823.0

asked Oct 28, 2019 by hgletifer (1.3k points)
0 votes
1 answer

Hi: I am trying to create a business rule that will stop a value change based on the existing value. For example, if the telephonenumber is 1234 for a group and has to ... the value it uses is the incoming value of the change, not the existing value. Thanks!

asked Jun 3, 2022 by crobitaille (80 points)
0 votes
1 answer

This is for license purposes and we do not want them visible in the Adaxes portal.

asked Oct 22, 2021 by jfrederickwl (20 points)
0 votes
0 answers

Hello, I want to automate the creation of a contact based on an existing AD Users. For example, the code in my custom command contains something like: new-mailcontact - ... a parameter after he run the Custom Command from the Web interface? Thanks in advance.

asked Apr 20, 2016 by tentaal (1.1k points)
0 votes
1 answer

Is it possible to script having users added (or removed) from a Security Group based on another AD Attribute? I have found ways to do this in Powershell (something like): ... just utilize the PS script and just run it through Adaxes on a timed fashion? Thanks!

asked Oct 7, 2014 by PunkinDonuts (360 points)
3,326 questions
3,026 answers
7,727 comments
544,678 users