Inject additional recipients in the Cc header

The following velocity script would allow you to inject additional recipients in the Cc header. As an example, the script will extract the list of watchers of the issue in the context and will inject them in the Cc header. This code base can be used for injecting additional headers/value

Pre-requisites

  • To prevent multiple notifications remove the Jira users from the desired Issue Event on your selected Notification scheme. (For this example we will be using watchers as shown below).

  • We are using the reporter as the recipient in which the Cc Header is added therefore the reporter must be notified of Notification. This can be done by going to Notifications > Jira user notification Project Mapping we must set the “Notify Me Condition” field. Either configure the field to “always” in which every associated users gets notified for every event or set to “forSelectedEvents” in which every associated users gets notified for the selected events (don't forget to select the events in next field).

A side effect with this approach that the reporter is not notified when he/she is the author of the change meaning that the email tied to the reporter will receive all the notifications.

The Script

Here is where the velocity script should be inserted (highlighted in red)

Ensure you do not change the existing code only add the provided script above the existing script.

 

This is a velocity script you will need to use in order to CC the watchers on the issue. The watchers will only get CC'd where the recipient of the Notification is the reporter.

#if($recipientUser && $recipientUser.equals($issue.getReporter())) #set ($watchers = $watcherManager.getWatchersUnsorted($issue)) #set ($watchersCount = $watchers.size()) #if ($watchersCount > 0) #set ($currentIndex = 0) #set ($watcherEmailList = " ") #foreach ($watcher in $watchers) #if($currentIndex == ($watchersCount - 1)) #set ($watcherEmailList = $watcherEmailList + " " + $watcher.getEmailAddress()) #else #set ($watcherEmailList = $watcherEmailList + " " + $watcher.getEmailAddress() + ",") #end #set ($currentIndex = $currentIndex + 1) #end $jemhUtils.addRawMailHeader("Cc", $watcherEmailList) #end #end