Skip to content
Permalink
Browse files

JENKINS-43268 adding global checkbox to allow sending to unregistered…

… emails. This is a workaround to a SCM plugin issue, like JENKINS-9016 and probably others (#161)
  • Loading branch information
aflat authored and davidvanlaatum committed Oct 27, 2017
1 parent dfb6bbb commit 19081b2aa3d32c479125b538c545fdd3065960f8
@@ -168,6 +168,11 @@
* Enables the "Watch This Job" feature
*/
private boolean enableWatching;

/**
* Enables the "Allow Unregistered Emails" feature
*/
private boolean enableAllowUnregistered;

public ExtendedEmailPublisherDescriptor() {
super(ExtendedEmailPublisher.class);
@@ -481,10 +486,19 @@ public boolean isWatchingEnabled() {
return enableWatching;
}

public boolean isAllowUnregisteredEnabled() {
return enableAllowUnregistered;
}

@SuppressWarnings("unused")
public void setWatchingEnabled(boolean enabled) {
this.enableWatching = enabled;
}

@SuppressWarnings("unused")
public void setAllowUnregisteredEnabled(boolean enabled) {
this.enableAllowUnregistered = enabled;
}

public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
@@ -617,6 +631,8 @@ public boolean configure(StaplerRequest req, JSONObject formData)
requireAdminForTemplateTesting = req.hasParameter("ext_mailer_require_admin_for_template_testing");

enableWatching = req.hasParameter("ext_mailer_watching_enabled");

enableAllowUnregistered = req.hasParameter("ext_mailer_allow_unregistered_enabled");

// specify List-ID information
if (req.hasParameter("ext_mailer_use_list_id")) {
@@ -28,11 +28,13 @@
import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.Cause;
import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.User;
import hudson.plugins.emailext.EmailRecipientUtils;
import hudson.plugins.emailext.ExtendedEmailPublisher;
import hudson.plugins.emailext.ExtendedEmailPublisherContext;
import hudson.scm.ChangeLogSet;
import hudson.tasks.MailSender;
@@ -199,7 +201,8 @@ private static void addUsers(final Set<User> users, final TaskListener listener,
}
}
} catch (UsernameNotFoundException x) {
if (SEND_TO_UNKNOWN_USERS) {

if (SEND_TO_UNKNOWN_USERS || ExtendedEmailPublisher.descriptor().isAllowUnregisteredEnabled() ) {
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"
@@ -86,7 +86,8 @@ f.section(title: _("Extended E-mail Notification")) {
f.optionalBlock(help: "/plugin/email-ext/help/globalConfig/debugMode.html", checked: descriptor.isDebugMode(), name: "ext_mailer_debug_mode", title: _("Enable Debug Mode"))
f.optionalBlock(help: "/plugin/email-ext/help/globalConfig/requireAdmin.html", checked: descriptor.isAdminRequiredForTemplateTesting(), name: "ext_mailer_require_admin_for_template_testing", title: _("Require Administrator for Template Testing"))
f.optionalBlock(help: "/plugin/email-ext/help/globalConfig/watching.html", checked: descriptor.isWatchingEnabled(), name: "ext_mailer_watching_enabled", title: _("Enable watching for jobs"))

f.optionalBlock(help: "/plugin/email-ext/help/globalConfig/allowUnregistered.html", checked: descriptor.isAllowUnregisteredEnabled(), name: "ext_mailer_allow_unregistered_enabled", title: _("Allow sending to unregistered users"))

f.advanced(title: _("Default Triggers")) {
f.entry(title: _("Default Triggers"), help: "/plugin/email-ext/help/globalConfig/defaultTriggers.html") {
hudson.plugins.emailext.plugins.EmailTrigger.all().each { t ->
@@ -0,0 +1,5 @@
<div>
Check this to allow emails to be sent to unregistered email addresses.
Security risk, see https://issues.jenkins-ci.org/browse/JENKINS-9016 for
more information
</div>

1 comment on commit 19081b2

@CheoWalker

This comment has been minimized.

Copy link

CheoWalker commented on 19081b2 Dec 21, 2017

I have Jenkins 2.60.2 running and this checkbox checked, but I still get the "Not sending mail to unregistered user" message.

Please sign in to comment.
You can’t perform that action at this time.