Mail Handler for ScriptRunner allows users to run groovy scripts when a message is received, expanding on Jira’s built-in mail handling capabilities. The Mail Handler processes incoming mail, automating tasks such as creating a new issue from the mail subject, creating users from the recipient list, or triggering workflow actions.
Add an Incoming Mail Handler
Navigate to System→Incoming Mail→Add Incoming Mail Handler from the Administration menu.
Specify a Name for the handler.
In Server, select either a POP3/IMAP mail server or the Local Files option (for an external service that writes messages to the file system).
Specify the Delay (in minutes); this is the frequency at which the mail handler runs.
In Handler, select ScriptRunner Mail Handler.
Select Next to add or write a custom groovy script.
Configuring a Mail Handler
Specify a Catch Email. Mail Handler only processes email messages whose To:, Cc:, or Bcc: lines contain the recipient specified in this field.
Provide a Forward Email address. An email is sent to the given address if an error occurred during Mail Handler execution.
This functionality is available for IMAP/POP3 configuration only.
Check the Strip Quotes option to remove quoted text from the message body, and populate the context variable
nonQuotedMessageBody(use this is exclude content from previous email replies).
Check Create Users to create new Jira users based on the From email address, if the message comes from an unrecognized address.
In Bulk, select the action that occurs for emails with the precedence Bulk, or emails with the Auto-Submitted header.
To enter a script manually, type the script in the Script Console.
Alternatively, click the File tab on the Script Console to upload a script file. Start typing the name of the file into the Script File field.
The file must be accessible on the server.
The ScriptRunner Mail Handler provides the following binding variables:
message- The email message the handler is going to handle.
messageis an instance of javax.mail.Message.
messageHandlerContext- Jira utility class which helps to create issues, comments, and attachments etc.
nonQuotedMessageBody- A non-quoted message body contains lines that do not start with a '>' or '|'.