24

I've setup Jenkins to send emails only to users who broke the build using email-ext plugin, but I'm getting this error:

Not sending mail to unregistered user user@example.com because your SCM claimed this was associated with a user ID ‘John Smith' which your security realm does not recognize; you may need changes in your SCM plugin

I don't really understand what this error means, is the problem in our SCM, or in the email plugin? The emails are taken from the commit history, should I register them somewhere so Jenkins will start working?

For reference, this is the code around the error message in the plugin's source code:

                    } catch (UsernameNotFoundException x) {
                        if (SEND_TO_UNKNOWN_USERS) {
                            listener.getLogger().printf("Warning: %s is not a recognized user, but sending mail anyway%n", userAddress);
                        } else {
                            listener.getLogger().printf("Not sending mail to unregistered user %s because your SCM"
                    ........

How do I enable SEND_TO_UNKNOWN_USERS?

The error message is also mentioned in this bug report.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • `static /* not final */ boolean SEND_TO_UNKNOWN_USERS = Boolean.getBoolean(MailSender.class.getName() + ".SEND_TO_UNKNOWN_USERS"); ` So... just figure out how to set that boolean since you have the sourcecode? – Shark Jul 27 '17 at 12:28
  • @Shark I have it for reference, I don't compile it from source. I need to set it from configuration somehow. – sashoalm Jul 27 '17 at 12:42
  • 1
    `-Dhudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true` perhaps ? as read [here](https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin) on the `email-ext` plugin wiki – Shark Jul 27 '17 at 12:48
  • Can this be set from the web interface? I tried setting it from Manage Jenkins -> Configure System -> Global Properties -> Environment Variables, but nothing happened. – sashoalm Jul 27 '17 at 13:14
  • Looks like the Email Extension plugin adds a checkbox to the system configuration: https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin – andybuckley Feb 26 '19 at 15:50

4 Answers4

40

For version V2.61 or above this can be configured via a radio button.

Go to

Manage Jenkins -> Configure System -> Extended E-mail Notification

and tick the radio button for Allow sending to unregistered users

enter image description here

Edit: If this does not work, see https://stackoverflow.com/a/45353810/492336 for another solution.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
sha12
  • 1,497
  • 1
  • 17
  • 14
  • 2
    Also you can set "Allowed Domains" to your company domains for example: @mycompany.com for security reasons – burtsevyg Dec 19 '18 at 10:54
  • 4
    "Allow sending to unregistered users" and "Allowed Domains" don't work in Jenkins ver. 2.164.1. – M-Razavi Apr 16 '19 at 04:10
  • 2
    "Allow sending to unregistered users" also didn't work in Jenkins ver. 2.198 – n8yoder Mar 12 '20 at 19:29
  • Hm, I was thinking about accepting this answer since it's the most upvoted, but the above 2 comments make me unsure about it. Does it work for everyone or not? – sashoalm May 27 '21 at 14:32
20

OK, after some experiments this is what I found out:

Jenkins takes the email part of the committer (not the author). For example for a commit message that looks like that:

Author: John Smith <author1@example1.com>  2017-07-27 17:15:39
Committer: John Doe <committer1@example2.com>  2017-07-27 17:15:39
Parent: 9c3ff18dda8ca6f7b7ac4ebab4c76d3c85891a33 (commit)
Branch: master

Jenkins will take "committer1", and create a brand new user under People with User ID "committer1" and email "". Unless that user has a password however, it will be considered unregistered so you need to go to Configure for that user and add a password field to it:

enter image description here

So this is one way to fix the error, but you have to do it for every user and in a big team it can be tedious.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
8

Put the line bellow in your jenkins startup script

-Dhudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true

The newest Jenkins security directive only allow sending mail to registered user. The line above bypass this configuration.

Joao Vitorino
  • 2,976
  • 3
  • 26
  • 55
  • 1
    How does Jenkins decide whether a user is registered? Does it check if the Author Name from SCM is the same as the User ID (as opposed to User Name) of an existing user? – sashoalm Jul 27 '17 at 13:16
  • Yes. If the committer names is joao.vitorino and there is a user with login joao.vitorino and email address configured, jenkins do the match and send the email. You can solve by adding the config I posted or configuring the user in jenkins – Joao Vitorino Jul 27 '17 at 13:29
  • 1
    You can also use configure Jenkins to use ActiveDirectory or LDAP to identify your development users, so you do not need to configure each user individually in Jenkins. – Steven Scott Jul 27 '17 at 15:43
  • 1
    Or put to [jenkins.xml](https://stackoverflow.com/questions/29539234/system-properties-management/40256264#40256264). There are [SEND_TO_USERS_WITHOUT_READ and SEND_TO_UNKNOWN_USERS](https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin) – it3xl Mar 14 '18 at 09:53
1

Given jenkins takes the first part of the email address and creates a user, I made my team have their jenkins user name be the first part of their email address. This removed any overhead of having to maintain two separate users.

Clarkey
  • 1,553
  • 5
  • 22
  • 34