Customizing Notification Emails
Overview
The email content generated by Codebeamer is completely customizable. The templates that are used to render the mails are found in the CODEBEAMER_HOME/tomcat/webapps/cb/config/templates/email directory. There is one set of 3 files for each email type:
1. A Groovy script (see *.groovy files) that determines whether emails are sent or not
2. A Velocity template (see *_subject.vm files) to specify the subject of the email.
3. A Velocity template (see *_body.vm files) to specify the body of the email.
Customizing the Email Content
Velocity is a powerful, yet simple template technology. For general information about the Velocity template language, read Velocity Engine Manual. Codebeamer supports every feature available in Velocity (conditions, cycles, arithmetic, etc.). The templates can be modified on-the-fly, there is no need to restart the container (Tomcat).
Velocity context for each Email Type
The following beans can be used in the email templates. These are available both in the subject and body templates.
Email Type
Objects
Any
originator (who performed the action), recipient,remoteAddress (if available).
artifact_comment_created
comment,artifact, artifact.project .
artifact_*
artifact, contentUpdated (boolean flag), diffHtml
forum_post_created
forumPost, forumPost.forum, forumPost.forum.project
lost_password
password (String), homeSite (URL as String)
project_created
project
project_join_*
project, comment (String).
scc_modification_committed
commit (the changeset itself), commit.changeFiles, commit.project, diffHtml, diffStats
send_email
body (String).
tracker_item_association_created
association, assocaition.fromDto, association.toDto, trackerItem, trackerItem.tracker, trackerItem.tracker.project
tracker_item_attachment_created
attachment, attachment.trackerItem, attachment.trackerItem.tracker, attachment.trackerItem.tracker.project
tracker_item_comment_created
comment, comment.trackerItem, comment.trackerItem.tracker, comment.trackerItem.tracker.project
tracker_item_*
trackerItem, trackerItem.tracker, trackerItem.tracker.project, modificationComment and modificationCommentFormat (if comment is not empty), modifiedProperties (collection).
user_*
user (the actual account the email is related to, it's not identical with the originator!)
wikipage_comment_created
same as for artifact_comment_created.
wikipage_*
same as for artifact_*, but wikiPage instead of artifact
Note that for the nested object (for example, trackerItem.tracker), only the id and name properties are fetched for performance reasons.
Examples
To display the project name in the subject of tracker issue creation emails, modify tracker_item_created_notification_email_subject.vm as:
New CB Tracker Item in ${trackerItem.tracker.project.name} "${trackerItem.summary}"

To display the severity of a tracker issue when it is updated, you have to iterate over it as a collection property in tracker_item_updated_notification_email_body.vm:
Severity:

#foreach($severity in $trackerItem.severities)

${severity.name}

#end

To display the full commit message in the email subject, remove the use of the textFormatter.abbreviate tool in scc_modification_committed_notification_email_subject.vm as:
CB Change Committed to [${commit.project.id}] ${commit.project.name} "${commit.message}"



#if(${commit.changeFiles.size()} == 1)

(1 change)

#else

(${commit.changeFiles.size()} changes)

#end



(+${diffStats.linesAdded} -${diffStats.linesRemoved})

Customizing the Email Sending
Codebeamer runs a Groovy scripts to decide whether to send a notification email to an addressee. For each mail and for each addressee, it evaluates a script that must return a boolean return value:
TRUE: Send the mail to the addressee.
FALSE: Skip this addressee.
Groovy is a full-blown scripting language that integrates very well with Java, so you have unlimited possibilities with this and in most of the cases it requires only minimal programming skills. Our only limitation is that there is one script for each email type and you can't customize it for each user. The default scripts that are shipped with Codebeamer will allow sending any email to all addressee:
return true

The scripts can be modified on-the-fly, there is no need to restart the container (Tomcat).
Examples
To disable tracker item creation emails in certain projects or trackers, modify tracker_item_created_notification_script.groovy by adding the appropriate project IDs or tracker IDs to the lists:
// list of project IDs, tracker IDs and tracker item IDs

// that will be ignored when sending notification emails

def ignoredProjects = [-1, -2]

def ignoredTrackers = [-1, -2]

def ignoredTrackerItems = [-1, -2]



// reject if listed

if(trackerItem.tracker.project.id in ignoredProjects ||

trackerItem.tracker.id in ignoredTrackers ||

trackerItem.id in ignoredTrackerItems) {

return false

}



return true

To restrict tracker item update emails only to certain property changes, check the modifiedProperties collection in tracker_item_updated_notification_script.groovy. In this example, the mail will be sent only when status is changed to Closed:
for(modifiedProperty in modifiedProperties) {

if(modifiedProperty.fieldName == "Status" && modifiedProperty.newValue == "Closed") {

return true;

}

}



return false;

Adding images to Emails
Normally the images are removed from emails: they are replaced by a an image looks like .
This happens for security reasons and also to prevent broken images in the emails which may happen in the user who looks at the email does not have a permission to view the referenced image(s).
However if you want to include images into your emails and keep them in your custom email templates then your options are:
Embed your image into the HTML template using Data URI scheme, so these images will be kept in your emails. For example this HTML markup will render an red dot:
<img src="data:image/png;base64,iVBORw0KGgoAAA

ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4

//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU

5ErkJggg==" alt="Red dot" />

Or use a special keepImageInEmails CSS class in your HTML markup to mark the images should be kept in your email. In the next example the image myImage.png will be preserved in your email because it has this special CSS class:
<img src="http://mysite/myimage.png" class="keepImageInEmails" />

* 
The email clients -like Google's gmail web interface- may not display the images in data-uri or even external images. This can happen because the embedded images may either break the layout of the Gmail web-page and/or the images are sometimes have security implications: for example some pages may use small hidden images to track your action whether you have opened/viewed the email or not. So always test in your environment if the email works as designed. Links: sTurn images on or off in Gmail
Was this helpful?