Check Error Mail Queue and transition issue

Hello all, 

I have a send custom email on post function transition.

I would like to check the error queue after the email is sent either by the same post function or script listener to see if the email has been sent with no errors. 

It takes approx. 12 mins after for the email to go to the error queue if the email is unsuccessful, so i need to post-pone my script to check the email queue 12 mins after post function. 

I've managed to compile the below Code to run in fast track transition so if the condition is true then it transitions its status: 

import java.util.concurrent.TimeUnit
TimeUnit.MINUTES.sleep(13) // Takes 13 mins after retry to go into error queue when unsuccessful
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.mail.queue.MailQueue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue 
Issue issue  = issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def mailQueue = ComponentAccessor.getComponent(MailQueue)
String key = issue.getKey()
String errorQueue = mailQueue.getErrorQueue()
if (errorQueue.contains(key))
	return true
		else false

But if i do this, the transition screen wont proceed and will be stuck in loading for 13 mins. 

What its suppose to do is, basically checks the error email queue when the email is sent 13 mins after and then identify if the issue key is in the error queue then it should transition to a "failed reply" status.

Is there any way around this or can anyone offer a better solution to check for the error queue after the email has been sent.

Many thanks, 



2 answers

1 accepted

1 votes

You'd have to start a new thread... but it seems like a bad solution.

new Thread({
    // do stuff

Why might the email fail to be sent?  Why does it take 12 minutes to get there?

If you must do this maybe consider using a service: to run every 10 mins and check the error queue, making sure to remove it from the queue once processed.


The email keeps on retrying to send for around 12 minutes, i think its a configuration on the server side. 

Thank you for recommending me service.

What i was trying to do is if there is a mail in the errorQueue, then it would transition that issue to a failed delivery status extracting the issue key from the subject. 

And service does exactly this. I've placed the above code to Escalation service and works like a charm. 




Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,844 views 12 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot