Sending emails from a Java application is not rocket science! But why bother if JIRA has its own APIs to do the job for you? I am talking about taking advantage of the issue event management in JIRA. We all know about the notification schemes in JIRA and how JIRA sends email to the various subscribers when an event is fired. All we need to do is to make use of this feature. Following are the simple configuration steps needed.
Now that the template is defined and the event added, we can write the code that feeds the relevant context for the template and then fires the event. In your plugin, all you needed is a few lines of code.
How about sending it only to selected people and not depending on the notification schemes? Like the share feature in JIRA5? i.e. send only to selected users? Replace the dispatchEvent with the following.
And that's all. The mail queue will take care of dispatching our message. I have attached the code of a simple servlet plugin which does both the approaches at the end of this page. After installing the plugin, it can be tested by accessing the servlet. Use a valid issue key and a receiver attribute if you are not using notification scheme. Example calls: http://localhost:8080/plugins/servlet/mailservlet?receiver=jobinkk&issue=DEMO-1 http://localhost:8080/plugins/servlet/mailservlet?issue=DEMO-1 Have a good day!
17 Comments
Jobin,
Reply
J-Tricks
7/10/2012 07:07:06 am
Matt, yes. It will be sent by the mail queue every N minutes as defined in the MailQueueService.
Reply
7/22/2012 11:49:02 pm
It is quite interesting to know this kind of emails sending process and will try the plugins you mention in the post .
Reply
Bastien
11/23/2012 03:06:42 am
Hi !
Reply
J-Tricks
11/23/2012 07:56:53 am
Which version of JIRA is it?
Reply
Bastien
11/25/2012 07:30:13 pm
My Jira version is 5.0.7
Bastien
11/25/2012 10:15:51 pm
I found a solution to my problem :
Reply
J-Tricks
11/26/2012 02:35:14 am
Great :)
Reply
J-Tricks
12/14/2012 12:47:57 am
You can do most of it when the plugin is enabled. See http://www.j-tricks.com/1/post/2012/03/plugin-lifecycle-events.html for details.
Reply
Shabbir K
2/12/2013 12:50:25 am
HI
Reply
J-Tricks
2/12/2013 01:53:23 am
You can try the method where you add recipients and add the mail item.
Reply
Matt Doar
2/14/2013 11:24:46 am
Shabbir, why not just define a notification scheme that uses a Custom Group Picker field. Then have the user populate the custom field and email will be sent to the groups in that field.
Reply
roark
3/25/2013 02:29:14 am
How do i include the package com.atlassian. jira in my project
Reply
J-Tricks
3/25/2013 03:47:25 am
Do you have the jira-api dependancy in the pom.xml? That will bring in most classes. Some of them are still part of core API and so you will have to add jira-core dependancy.
Reply
Subject will be something simple. We are going to keep it very simple!
2/26/2015 11:35:14 pm
:)
Reply
Your comment will be posted after it is approved.
Leave a Reply. |
AuthorJobin Kuruvilla - Works in Adaptavist as Head of DevOps Professional Services. Categories
All
Archives
October 2016
|