Send Custom Email Mail Queue Error Identifier

Deleted user March 15, 2017

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
adammarkham
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.
March 16, 2017

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.

Deleted user March 16, 2017

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!

Deleted user March 16, 2017


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

adammarkham
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.
March 17, 2017

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.

Deleted user March 19, 2017

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

adammarkham
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.
March 19, 2017

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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events