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

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

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

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

0 votes

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,095 views 13 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot