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

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 Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,775 views 18 21
Read article

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