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 vote

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 vote

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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

59 views 0 5
Read article

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