Jenkins email plugin doesn't send email to user who broke the build - email

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.

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
Edit: If this does not work, see https://stackoverflow.com/a/45353810/492336 for another solution.

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:
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.

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.

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.

Related

Notification for ’A pull request is created or updated‘ is not working when application-tier is Simplified-Chinese

- Version:
azure devops Dev17.M153.5
sql server 15.0.2000
- Reproducible Steps:
Install the azure devops 2019 1.1
Configure the application-tier as Simplified-Chinese
Finish the installation
Create the team notification for ’A pull request is created or updated‘
Check the mailbox
Information:
PR notification email was not received
Follow the instruction and we got the following message:
"messages":[{"level":1,"time":"11:23:40.2682787","message":
"设置电子邮件格式时出错。将改为发送一条错误消息。
MustacheExpressionInvalidException:对于表达式“stringFormat“在 {0} 中打开”event.secondaryToolName”找不到帮助程序“stringFormat“在”
#MustacheTemplatedExpression..ctor:0
#MustacheExpression.Parse:0
#ContributedTemplateServiceBase`1.ParseFieldToken:0
#ContributedTemplateServiceBase`1.ParseFieldToken:0
#ContributedTemplateServiceBase`1.ParseFieldToken:0
#ContributedTemplateServiceBase`1.ParseFieldToken:0
"
- We have tried :
Double-check the Why am I not getting an email ---- No issue is against the rules in the guidance
Try another notification type, such as "Work item is created" or "A build completes" ---- We can receive the related email
Remove the application-tier which has been initialized as Simplified-Chinese, and re-initialize the new application-tier as English-----The expected PR notification email was RECEIVED !!!
In order to narrow down the issue, you could try the following items:
Check whether you have the latest patch installed: https://learn.microsoft.com/en-us/azure/devops/server/release-notes/azuredevops2019u1?view=azure-devops
If you configure the application-tier as Simplified-Chinese again, would you be able to see the issue agine?
Check in other team projects to see whether you can reproduce this issue.
Create a new team project collection, and create a new team project in it, to see whether you can reproduce this issue.
Check the event log in Event Viewer, to see whether there is useful information.

Jenkins Ext email showing address not configured yet - even after setting up the System admins email

Jenkins Version : 2.251
I have configured the Extended E-mail Notification in my Jenkins and setup the System Admin e-mail address under Jenkins Location like this (e.g. "Jenkins Daemon <foo#acme.org>").
When I do a Test configuration by sending test e-mail, I'm getting a test mail from Jenkins with proper address.
But when my Job triggers a mail after completion, its coming as address not configured yet.
Please help me to solve this.
Thanks in advance.
I was also facing the same issue.
I was able to do it successfully with:
Freestyle job:
Add Post-build action > Editable email notification( from Email Extension plugin) >
The "project from" field > thesender#test.comzz
Declarative pipeline:
emailext body: 'abcd', from: 'thesender#test.comzz', replyTo: 'justTest#test.comzz', subject: 'test1', to: 'youremail#test.comzz'

Gerrit not sending emails

I have set up a Gerrit server and trying to make it send emails (for all events). But for some reason Gerrit doesn't send any emails. error_logs shows absolutely no data, that means it is not even trying to send emails.
Here is relevant part of my project.config for All-Projects:
[notify "demo"]
email = me#company.com
type = all
Here is my gerrit.config:
[gerrit]
basePath = git
canonicalWebUrl = http://hostname:8443/
[database]
type = h2
database = db/ReviewDB
connectionPool = true
poolLimit = 128
[index]
type = LUCENE
[auth]
type = LDAP
[ldap]
poolDebug = all
server = ldap://nod.company.com
accountBase = cn=users,dc=company,dc=com
accountEmailAddress = mail
referral = follow
[sendemail]
smtpServer = relay.company.com
smtpServerPort = 25
smtpUser = my_username
[container]
user = gerrit2
javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
heapLimit = 2g
[sshd]
listenAddress = *:29419
maxConnectionPerUser = 256
[automerge]
botEmail = me#company.com
[download]
scheme = ssh
[httpd]
listenUrl = http://*:8443/
maxThreads = 128
[cache]
directory = cache
[gitweb]
cgi = /usr/share/gitweb/gitweb.cgi
Environment: Ubuntu 14.04 and Gerrit 2.11.6.
I have tried to send emails from command line on this server and that works just fine.
All of my individual projects on Gerrit inherit access rights from All-Projects. I even tried adding the email section to each individual project but that didn't help either.
My colleague, who has his own Gerrit server that is able to send emails, looked into my issue and couldn't figure out what's wrong with my server. We both have same Linux version, Gerrit version, gerrit.config and project.config.
Ok, found the issues and fixed them. I had two issues, sharing for user reference.
I installed sendmail utility when logged in as a user other than smtpUser account mentioned in gerrit.config. After that I forgot to add the sendmail utility to /opt and hence the smtpUser's account from gerrit.config was not able to access the sendmail utility. Once I shared the sendmail utility with all user accounts, gerrit started sending emails.
To summarize, make sure the user account mentioned under smtpUser has sendmail available to it. Thanks everyone for your time.
gerrit wont send the email ONLY to the user that is also the smtpUser in gerrit.config. I was testing it by sending emails to only me, and hence it didnt work. I had to change to project config to add an email address other than my own email account.
I dont know if this is a gerrit bug or a gerrit feature. If a feature then not sure what is the use case for this !!
I hope this info helps other guys out there.
I had this problem after a recent Gerrit update (from 2.15 -> 3.2).
I checked the postfix logs in /var/log/maillog and they clearly showed that after the machine was rebooted following the Gerrit update no more mails arrived here.
Looking further into <gerrit-path>/logs/error_log (I had to look in rollated files) showed me that there seemed to be a problem with our mail template and also gave me the path to the offending file.
We previously used a custom mail template from https://gist.github.com/orgads/d8a61a1c10efeb7a4fafbcb6374167c3, the format of which seems to no longer be valid. I replaced this with the .soy.example file provided by Gerrit which fixed the issue.
For me, since I was trying to test emails by getting them to send to my own email, I had to go to settings (Gerrit 2.15.17 BTW), then preferences, under email notifications, select "every comment" in the dropdown menu.

In coming emails not updating issue fields in Redmine

I am trying to set up Redmine so that it can receive emails to create tickets .
The command I use to fetch emails is
rake --trace redmine:email:receive_pop3 RAILS_ENV="production" host=my.mail.server port=110 username=born#mydomain.com password=***** project=foobar
email contents are like
Project: foobar
Tracker: Bugz
Status: New
Priority: Normal
On receiving this email redmine created a new ticket . However files Tracker,Status and Priority is not getting updated with the values from email . Instead the entire email body is getting updated in Description field of the new ticket.
Are my emails not in the correct format ?
Redmine only allows setting attributes from the mail body which are explicitly enumerated on the command line.
You can specify which attributes are allowed to be set using the #allow_override# argument to the rake task similar to this:
rake redmine:email:receive_pop3 RAILS_ENV="production" ... allow_override=project,tracker,status,priority
Please see the documentation at http://www.redmine.org/projects/redmine/wiki/RedmineReceivingEmails#Issue-attributes for details.

How to send an email with Ansible

I'm trying to send an email using Ansible, but I can't understand how it works as I don't know how to provide user and password for such service (not specified in the documentation).
Both my machine and the email server are in the same network, but I need to be authenticated in order to send the email.
This is my yml file:
---
- name: Testing email
hosts: localhost
tasks:
- name: Send email
local_action: mail
host=mail.server.com
port=993
subject="Ansible test mail"
body="Testing email"
from=my#email
to="y#email
charset=utf8
And this is the related content of the hosts' file:
[localhost]
localhost ansible_connection=local
Any idea about how should I configure it? Thanks in advance.
Looking at the source code for the mail module ( https://github.com/ansible/ansible/blob/d1effecb2ef073e478c67a7ca39cf56708a66a48/library/notification/mail ) it doesn't look like it supports SMTP authentication.
It shouldn't be too hard to add support for it however. It would require adding the username and password parameters to the module, detecting if they've both been supplied, and if so, calling smtp.login() with those parameters.
In fact, it looks like there's two pull requests to do exactly that at the moment here
https://github.com/ansible/ansible/pull/7213
and here
https://github.com/ansible/ansible/pull/6667
So support will most likely be added in dev soon.