21

Jenkins refuses to send error mails to some users. In the log I found these messages:

....
Build step 'Maven Goals aufrufen' marked build as failure
Not sending mail to unregistered user user1@example.org
Sending e-mails to: user2@example.org
Finished: FAILURE

The user (user1) is listed in the admin people list. He also has an registered email (user1@example.org).

Jenkins Peoaple admin interface

So why is this user called an unregistered user?

When searching for this warning, I find several open JIRA issues such as https://issues.jenkins-ci.org/browse/JENKINS-43178 But these doesn't help me.

Is this a misconfiguration or a jenkins bug?

Matthias M
  • 12,906
  • 17
  • 87
  • 116
  • Is that user registered as Jenkins user? Check the configuration for that Jenkins task to see which users get a mail. And you should provide the version of your Jenkins in your question. – mvw May 23 '17 at 07:22
  • Thanks, good question :-) The user is listed under "People". I've added this remark to my description. – Matthias M May 23 '17 at 07:45

5 Answers5

16

There's Allow sending to unregistered users setting under Configure System menu at least in Jenkins >= 2.150.1.

juzzlin
  • 45,029
  • 5
  • 38
  • 50
  • I'm using Jenkins 2.361.1 and there checking "Allow sending to unregistered users" setting doesn't seem to have any effects. I'm still getting "Not sending mail to unregistered user". Any ideas? – finrod Nov 25 '22 at 14:37
9

The problem was (for me):

 SECURITY-372 (advisory) Emails were sent to addresses not associated with
 actual users of Jenkins.

I am using Jenkins with a Gerrit trigger for newly created Patchsets or published drafts. With this security "fix", Jenkins will try to "guess" the Username from the name before the email address. For Example in "Name Surname ", the "Name Surname" part will be the Username jenkins tries to lookup in the Jenkins UserDB, but that combination is not the same identifier that is used in our LDAP and thus, jenkins will not send emails....unless:

https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin#Email-extplugin-2.57.2(April10,2017)

If the security fix is undesirable in a particular instance, it can be disabled with either or both of the following two system properties:

    -Dhudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true: send mail to build culprits even if they do not seem to be associated with a valid Jenkins login.
    -Dhudson.tasks.MailSender.SEND_TO_USERS_WITHOUT_READ=true: send mail to build culprits associated with a valid Jenkins login even if they would not otherwise have read access to the job.

These JAVA_ARGS can be added in /etc/default/jenkins or /etc/sysconfig/jenkins, depending on your distribution.

Ilendir
  • 182
  • 1
  • 11
  • Thanks @Ilendir. This fix worked for me when problem signature was slightly different than that given in question: `Not sending mail to unregistered user johndoe@mycompay.com because your SCM claimed this was associated with a user ID ‘John Doe' which your security realm does not recognize; you may need changes in your SCM plugin` – Generic Ratzlaugh Nov 16 '17 at 18:40
  • 1
    Since V2.61 (October 27, 2017) it is possible to configure this via a checkbox on the "Configure System" page, so no need for command line arguments anymore. – Nitek Mar 20 '18 at 10:15
  • 1
    The checkbox didn't work for me, jenkins still refused to send email to "unregistered" users. I was only able to get it working by changing the JAVA_ARGS as in the answer. – Jason Day May 04 '18 at 14:35
  • @JasonDay I am new to Jenkins and facing the same issue.. could You please tell where or how you added these JAVA_ARGS. Thanks. – amidstCloud Nov 28 '18 at 22:08
  • @amidstCloud It's described in the answer we're commenting on. In my case, I added the JAVA_ARGS to /etc/sysconfig/jenkins . If you need more help you should ask a new question instead of using comments. – Jason Day Nov 29 '18 at 12:54
4

To clarify Matthias' answer: Even if a user account is created during a build (as the SCM provides information about the committer(s)), it is still an 'unregistered user' to Jenkins. Thus, no emails will be sent to that user.

If you navigate to the respective user account at <your-jenkins-URL>/asynchPeople/ you can configure this user account and enter a password for it. Theoretically, the user could login to Jenkins using this password, now. And as soon as a Jenkins user account has a password associated, it is no longer considered 'unregistered'. And will receive email notifications. Voila.

Hendrik
  • 56
  • 1
  • 3
4

From the OP it's not clear if they use LDAP, but here is some information that solved it for me and that I haven't found anywhere, including the Jenkins JIRA.

The following suggestion:

-Dhudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true

as well as:

Allow sending to unregistered users

and:

Create committer as Jenkins user

did not work for me. The first answer did put me on the track to a solution, though. It turns out that when using LDAP, Jenkins actually matches against the user name of the git committer. So if the git commit message is:

Committer: John Doe <John.Doe@company.com>  2019-05-27 19:12:00

Jenkins will take "John Doe", convert it to "john.doe" and try to match against LDAP. Now, if your LDAP user name is "john.doe" you're good, but in my case the company standard is "doejohn", which will lead to the dreaded message:

Not sending mail to unregistered user John.Doe@company.com

This message is very misleading since it shows the correct e-mail address instead of mentioning the invented (non-existing) user name. The solution for me was to configure the git user name to "doejohn":

$ git config --global user.name "doejohn"
3

The unregistered user had no jenkins password. After entering a password in the jenkins user password field, mails are sent to that user.

To enter the password

  1. navigate to the user management "People": http://jenkins/asynchPeople/ enter image description here
  2. select a user
  3. select "Configure"
  4. Enter the password in the password field

User password

Matthias M
  • 12,906
  • 17
  • 87
  • 116
  • 1
    Would you mind telling us which password field you are referring to? – Ilendir Jun 30 '17 at 09:00
  • Which password? Jenkins credentials or SCM user password. I have one Set at SCM but still no luck – Ankush T Sep 05 '17 at 14:16
  • @AnkushTehale Add the password to the jenkins credentials. I've added this statement to my answer. – Matthias M Sep 10 '17 at 19:58
  • @Ilendir Same answer as above: Add the password to the jenkins credentials. – Matthias M Sep 10 '17 at 19:59
  • 1
    So if I have oodles of developers I have to manually add passwords for each one? The configuration has a checkbox saying "email to unregistered users" and this checkbox is checked. Why doesn't that cover it? – legalize Jun 21 '18 at 19:44
  • Looks like the only way to get this to work without manually setting passwords is to set the configuration variable described above by @llendir in [jenkins.xml](https://stackoverflow.com/questions/29539234/system-properties-management/40256264#40256264) – legalize Jun 21 '18 at 19:59