Customizing Notification Emails #12427/HEAD / v631 |
Customizing Notification EmailsTable of Contents
OverviewEmail content generated by Codebeamer is completely customizable.The templates that are used to render the emails are found in the CODEBEAMER_HOME/tomcat/webapps/cb/config/templates/email directory. There is one set of 3 files for each email type:
Customizing the Email ContentVelocity 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.). Velocity context for each Email TypeThe following beans can be used in the email templates. These are available both in the subject and body templates.
Note that for the nested object (e.g. trackerItem.tracker), only the id and name properties are fetched for performance reasons. ExamplesTo 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 SendingCodeBeamer 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:
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. return true The scripts can be modified on-the-fly, there is no need to restart the container (Tomcat). ExamplesTo 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; Temporarily Disabling Notification Emails at High Memory UsageNotification emails may contribute to the server overload when the amount of free memory is low. You can use a Groovy script to temporarily disable these emails based on the memory usage:
ExplanationThe script temporarily disables the email notifications when Codebeamer uses more than 80% of the available memory. You can customize the maximum memory threshold using the MAX_MEMORY_USAGE flag. LoggingThe script also prints information to the server logs. See the following two examples:
INFO EMAIL_SCRIPT - Used memory 715M from maximum 2958M percentage:24% [GlobalScheduler_Worker-10] [37] {Req#=send-tracker-item-notification-job-4f02ea0c-9e11-4897-b754-6bd5b6a78dba, Sess#=send-tracker-item-notification-job-4f02ea0c-9e11-4897-b754-6bd5b6a78dba, serverId=server}
WARN EMAIL_SCRIPT - Skipping email sending because used memory: 85% is exceeding threshold of 80% [GlobalScheduler_Worker-6] [33] {Req#=send-tracker-item-notification-job-f5ff6dd5-cd41-4cd3-901f-2bdd494dd38a, Sess#=send-tracker-item-notification-job-f5ff6dd5-cd41-4cd3-901f-2bdd494dd38a, serverId=server Adding images to EmailsNormally 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:
The email clients -like Google's gmail web interface- may not display the imagesin 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 !
Listing All Objects Available in a Groovy ScriptThe following fragment lists all objects available inside a Groovy script: // Loop through all variables in the binding and log them: binding.variables.each { name, value -> // Use reflection to get the class type def clazz = value.getClass() logging.info("Variable: $name, Class: $clazz, value: $value"); } |
Fast Links
codebeamer Overview codebeamer Knowledge Base Services by Intland Software |
This website stores cookies on your computer. These cookies are used to improve your browsing experience, constantly optimize the functionality and content of our website, furthermore helps us to understand your interests and provide more personalized services to you, both on this website and through other media. With your permission we and our partners may use precise geolocation data and identification through device scanning. You may click accept to consent to our and our partners’ processing as described above. Please be aware that some processing of your personal data may not require your consent, but you have a right to object to such processing. By using our website, you acknowledge this notice of our cookie practices. By accepting and continuing to browse this site, you agree to this use. For more information about the cookies we use, please visit our Privacy Policy.Your preferences will apply to this website only.
Note that user-behavior analytics are being captured on this server for the purpose of improving the Codebeamer user experience.