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

This widget could not be displayed.

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

573 views 25 15
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