It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to check if Outgoing Mail is enabled or disabled via Scriptrunner

I setup some custom email notification at Post-function using Scriptrunner and even though the Outgoing Mail server is disabled, Scriptrunner is able to bypass that and still send emails.

 

I want to add a simple if statement and check if the Outgoing Mail server is Active or Disabled. Is there any way to do that using Scriptrunner?

 

Thank you!

2 answers

1 accepted

0 votes
Answer accepted

I didn't try turning it on and off, but there's a system property called "jira.mail.send.disabled" and the fact that my instance sends mail and has it's value false makes me thing it is it.

To retrieve it you can use 

import com.atlassian.jira.component.ComponentAccessor
ComponentAccessor.applicationProperties.getOption("jira.mail.send.disabled")

Well, I will be damned, it actually worked! I thank you so much for the answer. I was already running off in other direction, looking for other classes that would treat this system property differently.

What I am curious, if you can answer is: Where did you find this property?

Because in the documentation I found it was always 

atlassian.mail.senddisabled

I was just playing around with system properties once and found how to get their value. And for your case I just checked the System Info for something that contains "mail" because it sounded like a place to look for something like that :)

Yep, thank you so much! I glanced over the System info properties and there's all sorts of goodies to use in a lot of use cases.

It looks like this works for when you disable email in the Outgoing Mail with the button, but it doesn't work if email is disabled via startup flag (sigh)

Tested this on 8.5.1

If email is disabled via startup flag, reading the JVM Input Arguments works

import com.atlassian.jira.util.system.SystemInfoUtils
import com.atlassian.jira.util.system.SystemInfoUtilsImpl

SystemInfoUtils systemInfoUtils = new SystemInfoUtilsImpl()
String jvmArgs = systemInfoUtils.getJvmInputArguments()

isEmailDisabledStartup = false

if
(jvmArgs.contains('-Datlassian.mail.senddisabled=true')) {
isEmailDisabledStartup = true
}

I found that I could use isSendingDisabled() from the Settings class. Apparently whenever I call this method it always states that the 

atlassian.mail.senddisabled

always returns false...

Then if I go and make sure that the Outgoing Mail Server is really turned off but I try to Send a Test mail, it sends it without a hitch.

Could there be some other issue at play here :(? 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you