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
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
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.
It looks like you're new here. Sign in or register to get started.