Change the From: Address in Notifications

Introduction

You wish to set a custom From email address for your issue notifications.

In order for JEMH to successfully use a custom From address, the outgoing mail server being used must have the necessary configuration and/or permissions to send emails using that email address.

Example configuration

SMTP Server (in/out)

ppl.1.email@gmail.com

Jira user address (initiator)

jemhtesting2@gmail.com

Non-Jira user address (initiator)

jemhtesting3@gmail.com

Here, the Jira outbound mail server is showing the default from: address as ppl.1.email@gmail.com. It is this address that we will override.

Custom From address for Notifications for each Project Mapping/Project Mapping Rule (Event Listener driven notifications)

Possible with JEMH 1.7.x+

This method uses custom fields and the event listener to enable issue notifications to have a different From address depending on what project mapping or project mapping rule was used.  This allows a fine grained approach to configuring event notifications.  See How Do I Use Project Mappings for more information on how project mappings can be used.

Custom Field setup

If not already set up, create a Single Line Text Field type custom field.  This will be the custom field that holds our custom email address:

Ensure that your custom field is:

  • in the scope of the projects and issue types used

  • enabled in the field configuration associated with issues from your project

You can check this by using the "Where is my field?" functionality on an existing issue in your project. This is found under the "Admin" controls found next to the issue workflow actions.  Note that the field doesn't have to be visible in order to be used.

Profile setup

Next, we will configure our JEMH profile.  We are going to add a project mapping to the profile, then add a rule to the mapping.

  • Go to JEMH > Profiles and configure your chosen profile

  • Go to the Project Mappings section and click New Project Mapping

  • Select the Project that you want in Mapped Project field and Save it.

  • Go to Custom Field Defaults and click New Custom Field Defaults then edit it.

    We are now going to set a value for our custom address, so that when this project mapping is used the custom field will be given this value:

Static Value

Dynamic Value

Its possible to extract the ‘mailbox’ address that the mail was sent to (referred to as the Catchemail address), to do this, a Dynamic velocity script needs to be used:

 

  • Click Submit to save the changes, then choose any of mapping rules from the MAPPING RULES section and click New Domain Mapping, New Group Mapping or New Keyword Mapping.

  • In this example, we will create a simple domain mapping rule that maps issues to our project when they are from a particular address:

     

  • Click Save to save the changes

Event Listener/Notifications setup

We will now set up our project's Event Listener mapping in order for it to use the custom field.  We will be setting up the custom From address for the non-Jira user notifications. The same steps can also be applied for Jira user notifications.

  • Go to JEMH > Notification (Event Listener in the old JEMH versions)

  • Click Edit on your project event listener mapping

  • You will see a From: and Reply To: section.  We are focusing on the From address, however both can be set up in the same way by following this guide

  • For the setting Custom From: Custom Field, select the custom field that we gave a value in the profile project mapping

  • The Personal (name) used by the outgoing mail can also be set with either a custom field or a static text entry

  • Here is what our set up looks like:

     

  • Click Submit to save all changes

Result

For issue creation and other subsequent events, the custom email address is used for notifications.

Test case

The following test case is from: the non-Jira user, to the inbox address.

Created issue

Expected result of both the Jira and non-Jira user test cases:

 

The issue created with the Jira user has the reporter ‘jemh’ (a Jira account) and the issue created by the non-Jira user was created by the Default User 'admin':

Determining the From address

Personal
  1. If a configuration could be located and a custom Name is defined, use it, i.e. Custom Name in this example

  2. Failing this, the 'name' of the remoteUser making the change would be used

  3. Failing that, the 'name' taken from the senders email address would be used

Address
  1. If a Configuration could be located and a custom Email address is defined, use it, i.e. ppl.test.address@gmail.com in this example

  2. If not found, the project email address is used

  3. If not found, the server default address is used.

At this point, the sender will be "Custom Name" <ppl.test.address@gmail.com>

Examining the received emails

Non-Jira User

The Non-Jira notification shows the updated sender personal and address components, as defined within the Profile.

JIRA User

The Jira notification is the same.

Related articles