diff --git a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java index 9e64fb054..25062f72c 100644 --- a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java +++ b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java @@ -193,6 +193,9 @@ public class ExtendedEmailPublisher extends Notifier implements MatrixAggregatab */ public boolean disabled = false; + /* If true, will check for throttling limits before sending email */ + public boolean throttlingEnabled = false; + /** * How to theTrigger the email if the project is a matrix project. */ @@ -533,7 +536,8 @@ boolean sendMail(ExtendedEmailPublisherContext context) { } MimeMessage msg = createMail(context, fromAddress, session); debug(context.getListener().getLogger(), "Successfully created MimeMessage"); - if (EmailThrottler.getInstance().isThrottlingLimitExceeded() + if (getDescriptor().isThrottlingEnabled() + && EmailThrottler.getInstance().isThrottlingLimitExceeded() && !context.getTrigger().shouldBypassThrottling()) { context.getListener().getLogger().println("Could not send email. Throttling limit exceeded."); return false; @@ -569,7 +573,9 @@ boolean sendMail(ExtendedEmailPublisherContext context) { try { transport.connect(); transport.sendMessage(msg, allRecipients); - EmailThrottler.getInstance().incrementEmailCount(); + if (getDescriptor().isThrottlingEnabled()) { + EmailThrottler.getInstance().incrementEmailCount(); + } break; } catch (SendFailedException e) { if (e.getNextException() != null diff --git a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java index f732546f9..b6a9d4341 100644 --- a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java +++ b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java @@ -160,6 +160,11 @@ public final class ExtendedEmailPublisherDescriptor extends BuildStepDescriptor< */ private boolean enableAllowUnregistered; + /** + * Enables the email throttling feature + */ + private boolean throttlingEnabled = false; + private transient String smtpHost; private transient String smtpPort; private transient String smtpAuthUsername; @@ -300,6 +305,15 @@ public void setDefaultSuffix(String defaultSuffix) { this.defaultSuffix = Util.fixEmptyAndTrim(defaultSuffix); } + public boolean isThrottlingEnabled() { + return throttlingEnabled; + } + + @DataBoundSetter + public void setThrottlingEnabled(boolean throttlingEnabled) { + this.throttlingEnabled = throttlingEnabled; + } + @Restricted(NoExternalUse.class) Session createSession(MailAccount acc, ExtendedEmailPublisherContext context) { final String SMTP_PORT_PROPERTY = "mail.smtp.port"; diff --git a/src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/global.groovy b/src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/global.groovy index 9cf8943fc..d04baa309 100644 --- a/src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/global.groovy +++ b/src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/global.groovy @@ -76,6 +76,9 @@ f.section(title: _("Extended E-mail Notification")) { } } + f.entry(field: "throttlingEnabled", title: _("Enable Throttling"), help: "/plugin/email-ext/help/globalConfig/throttlingEnabled.html") { + f.checkbox() + } f.entry(field: "debugMode", title: _("Enable Debug Mode"), help: "/plugin/email-ext/help/globalConfig/debugMode.html") { f.checkbox() } diff --git a/src/main/webapp/help/globalConfig/throttlingEnabled.html b/src/main/webapp/help/globalConfig/throttlingEnabled.html new file mode 100644 index 000000000..a7a50caaa --- /dev/null +++ b/src/main/webapp/help/globalConfig/throttlingEnabled.html @@ -0,0 +1,5 @@ +