Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to update component while creating issue through scripted mail handler

Hello Community,

We have a requirement where components has to be updated while Issue created via mail handler.

Mail reached Mail_Q1 ---> Create Issue --> set the component as "Com1"  

Mail reached Mail_Q2 ---> Create Issue --> set the component as "Com2"  

Mail reached Mail_Q3 ---> Create Issue --> set the component as "Com3"  

So that we can differentiate Issues created from different mail queues. 

I have updated the script but getting error 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.exception.CreateException
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.jira.service.util.handler.MessageHandlerContext
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.mail.MailUtils
import javax.mail.Message
import javax.mail.internet.InternetAddress

final targetProjectKey = 'TEST'
final defaultReporterName = 'admin'
final defaultIssueType = 'Task'

def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor) as MessageUserProcessor
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.projectManager
def issueFactory = ComponentAccessor.issueFactory

def subject = message.subject as String
def issue = ServiceUtils.findIssueObjectInString(subject)

if (issue) {
// issue already exists so do nothing

def project = projectManager.getProjectObjByKey(targetProjectKey)

def user = userManager.getUserByName(defaultReporterName)
def reporterUser = messageUserProcessor.getAuthorFromSender(message) ?: user

def allCcRecipients = message.getRecipients(Message.RecipientType.CC) as List<InternetAddress>
def firstValidUser = allCcRecipients.findResult {

def issueObject = issueFactory.issue
def issueManager = ComponentAccessor.issueManager
def component = ComponentAccessor.projectComponentManager.findByComponentName(, "COM1")
issueObject.setIssueTypeId(project.issueTypes.find { == defaultIssueType }.id)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
firstValidUser ?
issueObject.setAssignee(firstValidUser as ApplicationUser) :
log.error('Unable to retrieve valid user from message CC list, issue will be created without assignee')

try {
(messageHandlerContext as MessageHandlerContext).createIssue(user, issueObject)
} catch (CreateException e) {
log.error('Error creating issue: ', e)

---error lines-------------

issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Can some help me to set the component also while creating an Issues through mail handler.


1 answer

0 votes

Welcome to the Atlassian Community!

Ploughing through someone else's code is hard work.  It is clear what the intention is, but could you tell us what the error messages are and what line they are pointing to in your code?

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events