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 Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,919 views 19 22
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