Skip to content

Commit

Permalink
JENKINS-43268 adding global checkbox to allow sending to unregistered…
Browse files Browse the repository at this point in the history
… 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 19081b2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Expand Up @@ -168,6 +168,11 @@ public final class ExtendedEmailPublisherDescriptor extends BuildStepDescriptor<
* Enables the "Watch This Job" feature
*/
private boolean enableWatching;

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

public ExtendedEmailPublisherDescriptor() {
super(ExtendedEmailPublisher.class);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
Expand Up @@ -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 ->
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/help/globalConfig/allowUnregistered.html
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.