Adding issue comments to emails

The default email template of Jira Email This Issue is prepared to render comments into the email body when the Add comments to outgoing emails option is enabled. However, if you develop your own custom email template not based on the default template, you'll have to add velocity template code to render the comments.

In order to add issue comments to the outgoing emails, two requirements must be met:

  • The option "Add comments to outgoing emails" has to be enabled in the corresponding component:

    • Email button (under OUTGOING EMAILS --> Manual Email Defaults --> Comments settings. Read more here.)

    • Bulk Email (under SETTINGS --> General Configuration --> Comments settings. Read more here.)

    • Post Function (under Issues --> WORKFLOWS --> Workflows. Read more here.)

    • Event Notification (under OUTGOING EMAILS --> Notifications --> Email settings. Read more here.)

  • A template fragment has to be added to your email template that will render the comments.

The template fragments are different for HTML and TEXT emails. You can use the Field Picker dropdown and select Comment.

Render comments in emails using templates based on themes

The new email template themes make it possible to render comments in emails easily in various ways.

Comment rendering macroDescriptionOrder

#renderComments($!issue)

Renders all comments of the issue which are not restricted to groups or roles nor are internal comments in Service Management.

Ascending

#renderCommentsInReverseOrder($!issue)

Renders all comments of the issue which are not restricted to groups or roles.

Descending

#renderServiceDeskPublicComments($!issue)

Same as #renderComments($!issue)

Ascending

#renderServiceDeskInternalComments($!issue)

Renders Service Management internal comments of the issue

Ascending

#renderAllComments($!issue)

Renders all comments of the issue. Comments may be internal or public, restricted or visible to all.

Ascending

#renderLastComment($!issue)

Renders the last comment entered in the issue

#renderComment()

Renders the comment entered during the operation

#renderCurrentComment()

Alias of #renderComment()

#renderIssueComments(<sorting> <number of comments> <restrictions>)

Generic, multi-purpose comment rendering macro. SINCE 8.0.3

Parameters:

<sorting>: asc or desc

<number of comments>: an positive integer number or all to render all comments matching <restrictions>

<restrictions>: comment restrictions. Its values are:

  • empty: render all comments regardless of the restrictions

  • none: render comments which are not limited to groups, roles or which are not internal in Service Management

  • public: render Service Management public comments

  • internal: render Service Management internal comments

Render Comments in emails using traditional templates

Comments in HTML Emails

It is possible to fully control how the comments are rendered in the email. The following codeblock example renders comments in HTML:

#if ($!emailDef.emailOptions.addComments)
<tr valign="top">
    <td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:${textSubtleColour};">#text("common.words.comments"):</strong>
    </td>
    <td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 0 10px 0;width:100%;">
        #foreach ($comment in $!publicComments)
        <p style="border-bottom: 1px solid #DDD;">
            <p style="font-weight: bold"><a href="$!baseurl/secure/ViewProfile.jspa?name=$!{comment.author}"><b>$!{comment.authorFullName}</b></a> - <b>$!{dateformatter.format($comment.created)}</b></p>
            <p>$!{rendererManager.getRenderedContent($!commentRendererType, $!comment.body, $issue.issueRenderContext)}</p>
        </p>
        #end
    </td>
</tr>
#end

Comments in Text Emails

It is possible to fully control how the comments are rendered in the email. The following codeblock example renders comments in Text:

-------------------------------------------------------------------------------
#if ($!emailDef.emailOptions.addComments)
$i18n.getText("common.words.comments"):
#foreach ($comment in $!publicComments)
$!{comment.authorFullName} - $!{dateformatter.format($comment.created)}
------------------
$comment.body
#end
#end

Reverse Comment List

Normally comments are rendered by date ascending. To render them the latest on top, you must reverse the list:

#set($publicComments = $!jetiFieldRenderer.reverse($!publicComments))

Last Comment

In operations when the users enter a comment (like issue update, or workflow transitions), the comment they enter can be referred to as $!comment or $!htmlComment depending on the content type of the template. In other cases, after reversing the comment list, you can access the last one easily:

#if($!publicComments && !$!publicComments.empty)
  #set($lastComment = $!publicComments.get(0))
  ...
#end

Without reversing the list first, access the last comment as:

#if($!publicComments && !$!publicComments.empty)
  #set($lastComment = $!publicComments.get($!publicComments.size()-1))
  ...
#end

Accessing all comments (even restricted ones)

To access all comments of an issue, use the $commentManager object.

#foreach ($comment in $!commentManager.getComments($!issue))
...
#end

Last updated