Email from Power Actions™ for Jira
Required apps
Level:Â BASIC
Use case
Sometimes project manager or any other Jira user who can view the issue, wants to send a personalized e-mail to certain email address. This message will not to be sent automatically, unless the user explicitly knows to whom he wants to send it.
This example shows how to do that by using Power Actions™ for Jira and the Simple Issue Language™.
Solution
Power Actions™ Custom Field that creates an email and sends it to the recipients enables you to resolve the use case.
Step 1: Create a new Power Actions Custom Field
- Go to Jira Administration > Issues > Custom Fields.
- Click Add Custom Field to add a new custom field.
- Select Power Actions™ Custom Field. Click Next.
- Give a name Email Issue and description to your field. Click Create.
- Check Issue screens you want your field to be reflected in.Â
- Click Finish.
Step 2: Configure your custom field
- To configure created custom field go to cog wheel menu. Click Configure.
- To create a button that triggers the dialog for the email details click Edit Buttons.
- To Add New Power Action™ insert a Button Text for instance Send Email. Click Add. Â
- 5 links for this button in the right of the screen will appear. The first three of them are the SIL™ scripts that controls it.Â
- The 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 Screen Script enables you to determine if the send email action requires additional data and builds a form that the user can fill in.
- The Action Script sends the email you want to the specified email addresses.
Step 3: Configure the Screen Script
Click the Edit Screen Script link. Write the following SIL™ script code in the panel. 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.
Screen Script Codeboolean 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;
- Save the code and go back to the Configuration page.
Step 4: Configure the Action Script
Click the Edit Script link. Write this SIL™ code in new page.
Action Scriptstring[] 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 provides the following actions:
- 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.
Note, you can use a template for the email which means that you 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 see the sendEmail routine.
Step 5: Build the email template
To create the email template go to Jira Administration > System > cPrime Plugin Configuration > Mail Sender Configuration.
A configuration Email Template Directory depicts the directory where the templates are kept. The rest of the email configuration is extracted from the standard Jira configuration.
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:
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 see the Email Templates page for detailed information. Also see the Mail Configuration section.
Example
You can now test this custom field by checking the issues you have selected in the first step of this recipe.
The Issue screen now has the Send Email button
The button screen is as follows
An example of a filled in form
Click Execute and that's all.
Working solution
In order to use this recipe with SIL Engine™ 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.
SIL Engine version 2.5.2 and higher does not need this configuration.
See also
Email Issue from Power Actions™ for Jira