Send Custom Email on Event

With this built-in listener, your Bitbucket instance will send email notifications automatically after one or more events has been triggered. You will just need to configure which events should this listener be listening to and then provide a subject and an email template, as well as the email format (plain text or HTML) and a list of recipients. There is also a conditions field, which can give more control over this functionality.

You can either create your own email templates or use one of the following samples that are included in the default installation of ScriptRunner:

Repository Forked

It provides information about the repository that has just been created and the users that performed that fork. This is how the configuration of the listener would look like:

As a result of that configuration, an email will be sent to the selected email addresses with a content similar to the following one:


User admin has forked the repository PROJECT_1/rep_1.
The name of the new repository is: PROJECT_1/myNewFork

Global Permissions Modified

If you would like to get notified every time a change is done in the Global permissions settings, you can use the following template:

An email like the following one will be sent over right after the permissions for a user have been modified:


User admin has modified the permissions for user user.
The highest global permission for this user is now: SYS_ADMIN

New Task Created in Pull Request

Users can also get notifications whenever a new task is created just by creating an listener similar to the following one:

In the image above, the event should be TaskCreatedEvent

If a new task is created, then the email addresses configured in the listener will receive an email with a content similar to this:


User admin has just created the following task: Copy content from branch FOO-123.
Please take a look at this pull request for more information: a modification on branch basic_branching

The content of the "to addresses" and "cc addresses" should be a list of emails separated by commas or spaces, being the following two examples correct: - email1@company.com, email2@company.com - email1@company.com email2@company.com

Additional Configuration in Emails

You may notice the syntax for getting content in the template is a bit clunky, as the template engine does not allow you to use the import keyword. Rather than doing this, you can pass in a config map to the bindings for both the subject and body templates. This is done in the Mail configuration section.

A simple example of a Mail configuration section that defines config variables for the RepositoryForkedEvent is:


config.username = $event.user.username
config.projectKey = $event.repository.origin.project.key
config.originName = $event.repository.origin.name
config.repoName = $event.repository.name

The subject template:


User $config.username has forked a repository

The body template:


User $config.username has forked the repository $config.projectKey/$config.originName.
The name of the new repository is: $config.projectKey/$config.repoName.

As a result of that configuration, an email will be sent to the selected email addresses with content similar to the following one:


User admin has forked the repository PROJECT_1/rep_1.
The name of the new repository is: PROJECT_1/myNewFork.


On this page