How can I add custom headers in JIRA e-mail notifications

Subhash Pillai September 17, 2014

I have a requirement to send an e-mail to another system for integration. Here I need to add a custom header (SMTP Header) with JIRA issue number, URL, status and priority. Apache Velocity Template files allows editing e-mail contents; not header. By default, JIRA adds some information (with issue id, time etc.) in e-mail headers. But I can’t add any additional information.

I read in support forums that it is possible through JIRA source code modification.Is there any free plug-in available for this modification? 

Could you please help on this?

Thanks,

Subhash

 

2 answers

0 votes
Benito Picarelli
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 25, 2014

Hello Subhash,

There is a improvement request already open to address this at the following link: https://jira.atlassian.com/browse/JRA-3933

If you check the comments, Matt pointed some code that he implemented to do somewhat the same of what you are trying toa ccomplish, I believe. Please see:

            final Email email = createEmail(recipientEmail, sender, senderFrom, subjectForRecipient, body, mimeType);
                        // START CHANGES
                        // contextParams is the Velocity context for email
                        try {
                            TemplateIssue issue = (TemplateIssue)contextParams.get("issue");
                            if (issue != null) {
                                Set<Label> labels = issue.getLabels();
                                StringBuffer sb = new StringBuffer();
                                if (labels != null) {
                                    for (Iterator it = labels.iterator(); it.hasNext(); ) {
                                        Label label = (Label)it.next();
                                        sb.append(label.getLabel());
                                        if (it.hasNext()) {
                                            // JIRA labels don't have spaces in them
                                            sb.append(" ");
                                        }
                                    }
                                    email.addHeader("X-JIRA-Labels", sb.toString());
                                    log.debug("Added labels headers '" + sb.toString() + "' to email " + email);
                                }
                            }
                        } catch (Exception ex) {
                            log.warn("Unable to add labels: " + ex.getMessage());
                        }
                        // END CHANGES

Also, I suggest that you vote on that ticket in order to increase it's visibility and likelyhood to be implemented.

Cheers

0 votes
Benito Picarelli
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 25, 2014

Hello Subhash,

There is a improvement request already open to address this at the following link: https://jira.atlassian.com/browse/JRA-3933

If you check the comments, Matt pointed some code that he implemented to do somewhat the same of what you are trying toa ccomplish, I believe. Please see:

            final Email email = createEmail(recipientEmail, sender, senderFrom, subjectForRecipient, body, mimeType);
                        // START CHANGES
                        // contextParams is the Velocity context for email
                        try {
                            TemplateIssue issue = (TemplateIssue)contextParams.get("issue");
                            if (issue != null) {
                                Set<Label> labels = issue.getLabels();
                                StringBuffer sb = new StringBuffer();
                                if (labels != null) {
                                    for (Iterator it = labels.iterator(); it.hasNext(); ) {
                                        Label label = (Label)it.next();
                                        sb.append(label.getLabel());
                                        if (it.hasNext()) {
                                            // JIRA labels don't have spaces in them
                                            sb.append(" ");
                                        }
                                    }
                                    email.addHeader("X-JIRA-Labels", sb.toString());
                                    log.debug("Added labels headers '" + sb.toString() + "' to email " + email);
                                }
                            }
                        } catch (Exception ex) {
                            log.warn("Unable to add labels: " + ex.getMessage());
                        }
                        // END CHANGES

Also, I suggest that you vote on that ticket in order to increase it's visibility and likelyhood to be implemented.

Cheers

Subhash Pillai September 28, 2014

Matt had commented that his code no longer works in JIRA 6.2.7

Suggest an answer

Log in or Sign up to answer