Skip to end of banner
Go to start of banner

Email from Power Actions for Jira

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 28 Next »

Required apps

Problem

Some times the project manager or any other Jira user that can view issue, wants to send a personalized e-mail to some email address. This message is not to be sent automatically, but only if the user explicitly wants to do it and to whoever he wants.

This example shows you how to do that by using Power Actions for Jira and the Simple Issue Language™.

Solution

To resolve this problem you will have to use a Power Actions custom field that creates an email and sends it to its recipients.

Step 1: create a new Power Actions Custom Field

First of all you'll need to create a new Power Actions custom filed, as follows:

  • Go to Administration page.
  • In this page go to the Issue section.
  • Here you will find a link named Custom Fields, you should click it.
  • Add a new custom field from the button in the right top named: "Add Custom Field".
  • Choose Power Actions Custom Field and click Next.
  • Name this newly created custom field: 'Email Issue'.
  • Choose applicable issue types and applicable context in order to view the new created custom field only on certain issues and projects.
  • Click Finish.

Step 2: Configure your custom field

Configure Email Issue custom field by doing the following:

  • Choose the cog icon at right of the screen for your Email Issue custom field. This is done by going to the Custom Fields page.
  • Choose the Configure link.
  • Now we'll need to create a button that will trigger the dialog for the email details.Click on the Edit Buttons link. You will find it on the bottom of the page in the section named Buttons.
  • Add New Power Action by creating a Button Text called: "Send Email". Press the Add button.
  • After you created this button you'll see 5 links for this button in the right of the screen.
  • The first three of them are the SIL scripts that controls it. The first script, named Condition Script, contains the condition for the button visibility. The default value is visible, so if you want all the user to see and action this button you can let the default script.
  • The second Script, named Screen Script, allows you to determine if the send email action requires additional data and builds a form that the user can fill in.
  • The third Script , named Action Script, sends the email you'll want to the specified email addresses.

Step 3: Configure the Screen Script

Click on the Edit Screen Script link. A panel will appear in which you will write the following SIL script code:

Screen Script Code
boolean isDisabled = false;
string [] ret = BA_createInput("Send to", "admin@kepler-rominfo.com", isDisabled);
ret = arraysConcat(ret, BA_createInput("CC", "", isDisabled));
ret = arraysConcat(ret, BA_createInput("Subject", "Your issue email title", isDisabled));
ret = arraysConcat(ret, BA_createTextArea("Email body", "Write your email here", isDisabled));
ret = arraysConcat(ret, BA_createFileUpload("Attachments", isDisabled));
return ret;

This code will create two input boxes for the email addresses (to and cc), another input box for the subject, an unlimited text area for Email body and a File Upload field for attachments.

Save the code and go back to the Configuration page for the

Step 4: Configure the Action Script

Click on the Edit Script link. A new page will appear in which you can write this SIL code:


Action Script
string[] to = replace(BA_getSingleValue(argv, "Send to"), ",", "|");
string[] cc = replace(BA_getSingleValue(argv, "CC"), ",", "|");
string subject = BA_getSingleValue(argv, "Subject");
string body = BA_getSingleValue(argv, "Email body");
string[] attachments = BA_getMultiValues(argv, "Attachments");
return sendEmail(userEmailAddress(currentUser()), to, cc, subject, body,"en_US", attachments);

This code makes the following operations:


  • Takes the email addresses that the user filled in and if there are more than one email creates a list with all of them.
  • Gets the subject of the email.
  • Builds the body of the message by using a template or by creating the email body from the text that the user filled in.
  • Gets the paths from the attachments from the "Attachments" field of the Email Issue custom field.
  • Sends the email with all the details filled by the user that send the email.

As we previously said we can use a template for the email which means that we have to create a template file that contains all the relevant fields of the issue. Also, for more information about sending an email using SIL consult the sendEmail routine page.

Step 5: Build the email template

After the installation of the plugin, in the "Administration" menu, a new option will appear named "Kepler General Parameters". Go to it and select "katl-commons" app from the Select plugin list. A configuration option named "Email Template Directory" depicts the directory where  the templates are kept. The directory path is relative to the jira.home.dir/kepler. The rest of the email configuration is extracted from the standard JIRA configuration (Administration->Mail Servers->SMTP Mail Server).

You can create a new template in this folder using your desired text editor. You can add the field values in the template by using the $field$ notation, where field is the name of the field you want to put in the text. Here is an example:

email Template
Hello,
 
This is a test template sent from $assignee$'s issue $key$.
$key$ is a $type$ that should be handled with $priority$ priority. At the moment $key$ is $status$.

More information:
$description$


$assignee$ wants to inform you about this issue.

This email was generated by the JIRA Blitz-Action plugin (https://marketplace.atlassian.com/plugins/com.keplerrominfo.jira.plugins.blitz-actions from http://jira-plugins.kepler-rominfo.com).

Email Templates

You can consult the Email Templates page for further information. Also consult the Mail Configuration page.


Test

You can now test this custom field by going to the issues you have selected in the first step of this recipe.

The Issue screen will have the Send Email button, like this:

The Screen of the Button will appear like this:

An example of a filled in form:

Click Execute and that's all.


You just saved 100 US dollars, so for sure you can eat at least a chocolate bar.


Working solution

In order to use this recipe with katl-commons version 2.5.0, 2.5.1, 2.0.10 due to some problems you will need to make the following settings:

  • Download the mail.jar and the activation.jar archives from the maven repository.
  • Create a folder on your system named endorsed and put those two archives in the folder.
  • If you are using Windows create a new environment variable named "JAVA_ENDORSED_DIRS" with the value "path_to_endorsed_folder". (Example: set JAVA_ENDORSED_DIRS="D:\JiraInstall\endorsed").
  • Or you can specify your endorsed folder as a java system property like so:
    -Djava.endorsed.dirs="D:\JiraInstall\endorsed" with your endorsed directory path.

Katl-commons version 2.5.2 and higher does not need this configuration.

  • No labels