Jira incoming mail handler processes the email using an incorrect user
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
When a user sends an email to the incoming mail handler, the email is either not processed or is processed using an incorrect user.
If the emails are not processed, warnings informing that the user is lacking application access can be observed in the atlassian-jira-incoming-mail.log
files, even though within the UI the user does have application access.
2019-01-01 20:00:00,000 WARN [Jira Mailhandler] Caesium-1-4 anonymous Jira Mailhandler Jira Mailhandler[10001]: Cannot create issue due to invalid license: [Sorry, you can't create any issues right now, as you need to have access to a Jira application to be able to create issues. To gain application access you need to be a member of a group assigned to an application.]
Cause
When multiple users with the same email address exist in the Jira database, Jira will use the first username that matches the email address.
For example:
The instance has the following users in the database.
ID | DIRECTORY_ID | ACTIVE | LOWER_USER_NAME | LOWER_EMAIL_ADDRESS |
---|---|---|---|---|
50 | 1 | 0 | catlassian | charlie.atlassian@mail.com |
68 | 10001 | 1 | charlie.atlassian | charlie.atlassian@mail.com |
In this scenario, directory 10001 is the topmost directory.
In the Jira UI, the user catlassian
will be disabled and does not have application access. However, if an email is received by charlie.atlassian@mail.com, the application will select the user catlassian
to create an issue or comment as this user has a lower ID and is thus queried prior to the correct user. This will result in the following error:
2019-01-01 20:00:00,000 WARN [Jira Mailhandler] Caesium-1-4 anonymous Jira Mailhandler Jira Mailhandler[10001]: Cannot create issue due to invalid license: [Sorry, you can't create any issues right now, as you need to have access to a Jira application to be able to create issues. To gain application access you need to be a member of a group assigned to an application.]
Diagnosis
This behavior can be verified by querying the database for the email address. For example, for the email address charlie.atlassian@mail.com:
SELECT id, directory_id, active, lower_user_name, lower_email_address FROM cwd_user WHERE lower_email_address = 'charlie.atlassian@mail.com';
Output:
ID | DIRECTORY_ID | ACTIVE | LOWER_USER_NAME | LOWER_EMAIL_ADDRESS |
---|---|---|---|---|
50 | 1 | 0 | catlassian | charlie.atlassian@mail.com |
68 | 10001 | 1 | charlie.atlassian | charlie.atlassian@mail.com |
Workaround
There are two workarounds for this issue;
- Align the username between the two directories.
- If the first option is not possible, modify the email address of the incorrect user so that it no longer matches an existing user.
UPDATE cwd_user SET email_address = 'inactive@localhost', lower_email_address = 'inactive@localhost' WHERE lower_email_address = 'charlie.atlassian@mail.com' AND id = '50';
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.