# 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](https://docs.meta-inf.hu/email-this-issue/email-this-issue-for-jira-server-data-center/documentation/outgoing-emails/sending-manual-emails/manual-email-default-settings).)
  * Bulk Email (under **SETTINGS** --> **General Configuration** --> **Comments settings**. Read more [here](https://docs.meta-inf.hu/email-this-issue/email-this-issue-for-jira-server-data-center/documentation/administration/general-configuration).)
  * Post Function (under **Issues** --> **WORKFLOWS** --> **Workflows**. Read more [here](https://docs.meta-inf.hu/email-this-issue/email-this-issue-for-jira-server-data-center/documentation/outgoing-emails/workflow-post-functions).)
  * Event Notification (under **OUTGOING EMAILS** --> **Notifications** --> **Email settings**. Read more [here](https://docs.meta-inf.hu/email-this-issue/email-this-issue-for-jira-server-data-center/documentation/outgoing-emails/event-notifications).)
* 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**.

![](https://4173056255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY44m7ZY1jU4Arh2tzwNn%2Fuploads%2FbRezwzCPqqDTRrkrV1DX%2Foutgoing_27.jpg?alt=media\&token=36281a48-bd32-4779-91f4-79c167b9d5bf)

### Render comments in emails using templates based on themes <a href="#addissuecommentstoemails-rendercommentsinemailsusingtemplatesbasedonthemes" id="addissuecommentstoemails-rendercommentsinemailsusingtemplatesbasedonthemes"></a>

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

<table><thead><tr><th width="250.33333333333331">Comment rendering macro</th><th width="319.03587903639163">Description</th><th>Order</th></tr></thead><tbody><tr><td><code>#renderComments($!issue)</code></td><td>Renders all comments of the issue which are not restricted to groups or roles nor are internal comments in Service Management.</td><td>Ascending</td></tr><tr><td><code>#renderCommentsInReverseOrder($!issue)</code></td><td>Renders all comments of the issue which are not restricted to groups or roles.</td><td>Descending</td></tr><tr><td><code>#renderServiceDeskPublicComments($!issue)</code></td><td>Same as #<code>renderComments($!issue)</code></td><td>Ascending</td></tr><tr><td><code>#renderServiceDeskInternalComments($!issue)</code></td><td>Renders Service Management internal comments of the issue</td><td>Ascending</td></tr><tr><td><code>#renderAllComments($!issue)</code></td><td>Renders all comments of the issue. Comments may be internal or public, restricted or visible to all.</td><td>Ascending</td></tr><tr><td><code>#renderLastComment($!issue)</code></td><td>Renders the last comment entered in the issue</td><td><br></td></tr><tr><td><code>#renderComment()</code></td><td>Renders the comment entered during the operation</td><td><br></td></tr><tr><td><code>#renderCurrentComment()</code></td><td>Alias of <code>#renderComment()</code></td><td><br></td></tr><tr><td><code>#renderIssueComments(&#x3C;sorting> &#x3C;number of comments> &#x3C;restrictions>)</code></td><td><p>Generic, multi-purpose comment rendering macro. <mark style="color:green;">SINCE 8.0.3</mark></p><p>Parameters:</p><p><code>&#x3C;sorting></code>: <code>asc</code> or <code>desc</code></p><p><code>&#x3C;number of comments></code>: an positive integer number or <code>all</code> to render all comments matching <code>&#x3C;restrictions></code></p><p> <code>&#x3C;restrictions></code>: comment restrictions. Its values are:</p><ul><li><code>empty</code>: render all comments regardless of the restrictions</li><li><code>none</code>: render comments which are not limited to groups, roles or which are not internal in Service Management </li><li><code>public</code>: render Service Management public comments</li><li><code>internal</code>: render Service Management internal comments</li></ul></td><td><br></td></tr></tbody></table>

### Render Comments in emails using traditional templates <a href="#addissuecommentstoemails-rendercommentsinemailsusingtraditionaltemplates" id="addissuecommentstoemails-rendercommentsinemailsusingtraditionaltemplates"></a>

#### Comments in HTML Emails <a href="#addissuecommentstoemails-commentsinhtmlemails" id="addissuecommentstoemails-commentsinhtmlemails"></a>

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 <a href="#addissuecommentstoemails-commentsintextemails" id="addissuecommentstoemails-commentsintextemails"></a>

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 <a href="#addissuecommentstoemails-reversecommentlist" id="addissuecommentstoemails-reversecommentlist"></a>

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 <a href="#addissuecommentstoemails-lastcomment" id="addissuecommentstoemails-lastcomment"></a>

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) <a href="#addissuecommentstoemails-accessallcomments-evenrestrictedones" id="addissuecommentstoemails-accessallcomments-evenrestrictedones"></a>

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

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