Send an email from Power Actions™

Problem

As a project manager or any other Jira user who can view an issue, you want to send a personalized email to certain email address. This email should not be sent automatically, unless the recipient is already known.

Solution

You can solve this problem using a Power Actions™ Custom Field that creates an email and sends it to the selected recipients.

Step 1: Create a new Power Actions Custom Field

  1. Go to the Administration page.

  2. In the Issue section, click Custom Fields.

  3. Click the Add Custom Field button in the upper-right corner to add a new custom field.

  4. Select the Power Actions™ Custom Field option. Click Next.

  5. Rename the new custom field to Email Issue and add a description. Click Create.

  6. Select the Issue screens where you want your field to be displayed. 

  7. Click Finish.

Step 2: Configure your Power Actions™ Custom Field

  1. To configure the Email Issue custom field, select the cog icon on the right.

  2. Go to the Custom Fields page to find your Email Issue custom field.

  3. Click Configure.

  4. To create a button that triggers the email sending action, go to the Buttons section at the bottom of the page. Click the Edit Buttons link.

  5. Click Add New Power Actions™ and enter Send Email as the button name. Click Add.

  6. Five links for this button are now displayed on the right of the page. The first three are the SIL™ scripts that control it. They are:

    • The Condition Script. It contains the condition for the button visibility. The default value is visible (the user can see and click this button).

    • The Screen Script. It allows you to determine if the email sending action requires additional data and creates a form that the user can fill in.

    • The Action Script. It sends the email you want to the specified email addresses.

Step 3: Configure the Screen Script

  1. Click Edit Screen Script. Enter the following SIL™ script code into the panel.

    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 creates:

    • two text boxes for the email addresses (To and CC),

    • an text box for the subject,

    • a text box with no character limit for the email body,

    • File Upload field for attachments.

  2. Save the code and go back to the Configuration page.

Step 4: Configure the Action Script

Click Edit Script. Enter the below SIL™ code in the new page.

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 produces the following actions:

  • Retrieves the email addresses entered by the user. If there are more than one email, it creates a list containing all of them.

  • Retrieves the subject of the email.

  • Builds the message body by using a template or by creating the email body from the text entered by the user.

  • Retrieves the paths for 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.

You can use a template for the email. In this case, you have to create a template file containing all the relevant fields of the issue. For more information on sending an email using SIL, go to the sendEmail routine page.

Step 5: Build the email template

To create the email template, go to Jira Administration > System > Power Plugins Configuration > Mail Sender Configuration.

A configuration Email Template Directory indicates the folder where the templates are stored. The rest of the email configuration is extracted from the standard Jira configuration.

You can create a new template in this folder using your preferred text editor. You can add the field values to the template by using the $field$ notation, where field is the field name you want to enter into 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).

For more information, go to Email Templates and Mail Configuration.

Example

You can now test this custom field.

Go to the issues you selected in the first step of this recipe. The issue screen now displays the Send Email button as below:

The button screen is displayed.

Here is an example of a filled-in form:

Click Execute.