Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Mihai_Perdum June 17, 2019

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

1 vote
Answer accepted
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2019

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")
Mihai_Perdum June 17, 2019

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
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2019

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 :)

Mihai_Perdum June 18, 2019

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.

Martina Riedel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2019

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

Martina Riedel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2019

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
}

Like # people like this
j.hoffmann July 7, 2021

Hey

I know I'm late to the party, but your snippet here helped me out a ton. Thanks, @Martina Riedel 

Best

0 votes
Mihai_Perdum June 17, 2019

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