Send Custom Email Mail Queue Error Identifier

Hi All, 

 

Im currently using JIRA 6.3.3 to send custom emails out via issues.

Im wondering if there is a way to identify when a particular email gets to the error mail queue and returns some sort of value?

 

Cheers, 

Pon

1 answer

1 vote

You could have a service in ScriptRunner which runs at regular intervals to check the error queue.

In the example below we get all the items on the error queue and log out the date it was put on the queue and the email subject.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.queue.MailQueue

def mailQueue = ComponentAccessor.getComponent(MailQueue)

def errorQueue = mailQueue.getErrorQueue()

def errorItems = []

errorItems.addAll(errorQueue)

errorItems.each { item ->
    log.warn "$item.dateQueued - $item.subject"
}

Unfortunately I can't see a specific event fired when an item is put on the error queue otherwise you could have used a listener for each item.

awesome, just what i needed, the email subject is static and has the issue key which i can feed back into the same issue. 

 

Thanks!


Hey Adam, 

 

Im just curious what this does - 

errorItems.each { item ->
    log.warn "$item.dateQueued - $item.subject"
}

i have the full working code below that comments on the same ticket if there is an error: 

 

import java.util.concurrent.TimeUnit
TimeUnit.SECONDS.sleep(12) // Takes 12 mins after retry to go into errpr queue
 
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue 
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.mail.queue.MailQueue

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

def mailQueue = ComponentAccessor.getComponent(MailQueue)
 
def errorQueue = mailQueue.getErrorQueue()
 
String s = errorQueue
s = s.substring(s.indexOf('[') +1 , s.indexOf(']'));
s = s.substring(s.indexOf('[') +1);

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(s)

def emailAdr = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(10301));

String errorMsg = "Error Sending Email to Email Address: " + emailAdr

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()

ComponentAccessor.getCommentManager().create(issue, currentUser, (String)errorMsg, false)

placed into post function

 

Cheers 

Pon

That part of the script basically just goes through each MailQueueItem from the error queue and logs out the subject and date of each item.

I was trying to demonstrate how to get the various fields for each item.

Nice example by the way.

Ahh awesome, thank you for explaining. 

 

i 've found a better way with post function detection using fast track transition 

import java.util.concurrent.TimeUnit
TimeUnit.MINUTES.sleep(12) // Takes 12 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

 

Sorry just another question, because im quite new to this. 

 

How do i impletement the hasError()  from the Class AbstractMailQueueItem


Not sure if this was something im looking for but im also trying to flag error in the mail queue


cheers, 

Pon

If you are getting items from the error queue than hasError() should be true. So you shouldn't have to implement that.

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 ...

3,265 views 14 20
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