Failing to run a built-in script in Confluence Scriptrunner
Asked by Dimitris Danampasis:

I am trying to create a Job in Scriptrunner using one the built-in scripts: **Old Content Notifier** .   
![2020-09-15 08_52_18-Jobs.png](/t5/image/serverpage/image-id/110382i4B281DC07DCB285D/image-dimensions/417x280?v=v2 "2020-09-15 08_52_18-Jobs.png")

An error appears when I am running the job manually:
> Error: javax.mail.Provider: Provider com.sun.mail.imap.IMAPProvider not found
>
> java.util.ServiceConfigurationError: javax.mail.Provider: Provider com.sun.mail.imap.IMAPProvider not found at com.atlassian.confluence.jmx.JmxSMTPMailServer.doSendWithMessageIdSupport(JmxSMTPMailServer.java:97) at com.atlassian.confluence.jmx.JmxSMTPMailServer.send(JmxSMTPMailServer.java:79) at com.atlassian.mail.server.SMTPMailServer$send$0.call(Unknown Source) at com.onresolve.scriptrunner.canned.confluence.jobs.TimedArchivalNotification.sendEmail(TimedArchivalNotification.groovy:227) at com.onresolve.scriptrunner.canned.confluence.jobs.TimedArchivalNotification$_execute_closure1.doCall(TimedArchivalNotification.groovy:161) at com.onresolve.scriptrunner.canned.confluence.jobs.TimedArchivalNotification$_execute_closure1.doCall(TimedArchivalNotification.groovy) at com.onresolve.scriptrunner.jobs.ConfluenceIdentitySwitchingService$_switchIndentityAndExecute_closure1.doCall(ConfluenceIdentitySwitchingService.groovy:30) at com.onresolve.scriptrunner.jobs.ConfluenceIdentitySwitchingService$_switchIndentityAndExecute_closure1.doCall(ConfluenceIdentitySwitchingService.groovy) at com.atlassian.confluence.user.AuthenticatedUserImpersonator$2.call(AuthenticatedUserImpersonator.java:118) at com.atlassian.confluence.user.AuthenticatedUserImpersonator$1.call(AuthenticatedUserImpersonator.java:101) at com.atlassian.confluence.user.AuthenticatedUserImpersonator.asUser(AuthenticatedUserImpersonator.java:82) at com.atlassian.confluence.user.AuthenticatedUserImpersonator$asUser.call(Unknown Source) at com.onresolve.scriptrunner.jobs.ConfluenceIdentitySwitchingService.switchIndentityAndExecute(ConfluenceIdentitySwitchingService.groovy:29) at com.onresolve.scriptrunner.jobs.IdentitySwitchingService$switchIndentityAndExecute.call(Unknown Source) at com.onresolve.scriptrunner.canned.confluence.jobs.TimedArchivalNotification.execute(TimedArchivalNotification.groovy:165) at com.onresolve.scriptrunner.canned.confluence.jobs.TimedArchivalNotification.execute(TimedArchivalNotification.groovy)

The configuration of the mail server is fine and there is no issue with the sending confluence sending mails. We are running on **Confluence v7.2** and **Scriptrunner v6.7**

Any ideas on how to fix that?


Answers:
author: Joshua Yamdogo @ Adaptavist
body: Hi Dimitrios,

We are aware of the exception being thrown whenever the Old Content Notifier job is ran manually. We have created an issue in our backlog here: <https://productsupport.adaptavist.com/browse/SRCONF-1413>

If you would like to go ahead and watch that issue, you'll receive a notification whenever the bug has been resolved.

Apologies for the inconvenience,

Josh

comments: author: Dimitris Danampasis
body: Good to know. Thanks for the response.


author: Muhammad Ramzan_Atlassian Certified Master_
body: Hi [Joshua Yamdogo @ Adaptavist](/t5/user/viewprofilepage/user-id/1124621) ,

I am running my local instance at localhost, previously i was able to send emails through the script but now its throwing the same error as mentioned above. Could you please advise

```
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.mail.Email

sendEmailToUsers("ramzan.danish@gmail.com", "", "test subject", "test body")

def sendEmailToUsers(String emailAddress, String bccEmail, String subject, String body) {

        def mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
        if (emailAddress) {
            if (mailServer) {
                Email email = new Email(emailAddress)
                email.setMimeType("text/html")
                email.setSubject(subject)
                email.setBcc(bccEmail)
                email.setBody(body)
                mailServer.send(email)
            }
        }


    }
```

```
java.util.ServiceConfigurationError: javax.mail.Provider: Provider com.sun.mail.imap.IMAPProvider not found at java.util.ServiceLoader.fail(ServiceLoader.java:239) at java.util.ServiceLoader.access$300(ServiceLoader.java:185) at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372) at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) at java.util.ServiceLoader$1.next(ServiceLoader.java:480) at javax.mail.Session.loadProviders(Session.java:964) at javax.mail.Session.<init>(Session.java:254) at javax.mail.Session.getInstance(Session.java:281) at com.atlassian.mail.server.managers.AbstractMailServerManager.getSession(AbstractMailServerManager.java:56) at com.atlassian.mail.server.AbstractMailServer.getSessionFromServerManagerInternal(AbstractMailServer.java:445) at com.atlassian.mail.server.AbstractMailServer.getSessionFromServerManager(AbstractMailServer.java:428) at com.atlassian.mail.server.impl.SMTPMailServerImpl.getSession(SMTPMailServerImpl.java:157) at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendWithMessageId(SMTPMailServerImpl.java:180) at com.atlassian.mail.server.impl.SMTPMailServerImpl.send(SMTPMailServerImpl.java:174) at com.atlassian.mail.server.SMTPMailServer$send.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127) at com.techclimbs.scriptrunner.upwork.Chris.Task5.Script21.sendEmailToUsers(Script21.groovy:18) at com.techclimbs.scriptrunner.upwork.Chris.Task5.Script21.run(Script21.groovy:6) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) at javax.script.ScriptEngine$eval.call(Unknown Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:174) at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$3.callCurrent(Unknown Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:293) at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$2.callCurrent(Unknown Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScript(AbstractScriptRunner.groovy:305) at com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint$_execFromJson_closure2.doCall(UserScriptEndpoint.groovy:156) at com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint$_execFromJson_closure2.doCall(UserScriptEndpoint.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:37) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119) at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy:350) at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:37) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119) at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder.withRecording(ScriptExecutionRecorder.groovy:13) at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder$withRecording.call(Unknown Source) at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl.execute(DiagnosticsManagerImpl.groovy:348) at com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint.execFromJson(UserScriptEndpoint.groovy:147) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$ResponseOutInvoker.lambda$_dispatch$0(DispatchProviderHelper.java:181) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper.lambda$invokeMethodWithInterceptors$0(DispatchProviderHelper.java:81) at com.atlassian.plugins.rest.common.interceptor.impl.DefaultMethodInvocation.invoke(DefaultMethodInvocation.java:53) at com.atlassian.plugins.rest.common.expand.interceptor.ExpandInterceptor.intercept(ExpandInterceptor.java:42) at com.atlassian.plugins.rest.common.interceptor.impl.DefaultMethodInvocation.invoke(DefaultMethodInvocation.java:53) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper.invokeMethodWithInterceptors(DispatchProviderHelper.java:106) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$ResponseOutInvoker._dispatch(DispatchProviderHelper.java:180) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:160) at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:829) at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:70) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:62) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:37) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:55) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:43) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:62) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:37) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.lambda$doFilter$0(DelegatingPluginFilter.java:57) at com.atlassian.plugins.rest.module.servlet.RestServletUtilsUpdaterFilter.doFilterInternal(RestServletUtilsUpdaterFilter.java:23) at com.atlassian.plugins.rest.module.servlet.RestServletUtilsUpdaterFilter.doFilter(RestServletUtilsUpdaterFilter.java:35) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:62) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:37) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.lambda$doFilter$0(DelegatingPluginFilter.java:57) at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:62) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:37)
```


Tags: confluence-server

email

script

scriptrunner

server