Hello Community,
I am currently writing a script for using the script mail handler for achieving the following use case.
- We are already using script runner for sending out email to non jira users.
- When those non-jira users reply to the email, it should come back to Jira and transition the ticket as well as add comment onto it
As per what I have read in the documentations, it is possible to do so using the script mail handler in the incoming mail handler settings.
In the document it shows how to get the commits from 3rd party app like bitbucket etc.
But in my case it will be coming from email. Also, I am not sure how to set the comment author since the actual author will be a non jira user.
I managed to write the following code it does seem to be working. So far it does not give any errors.
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.mail.MailUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.service.util.handler.MessageUserProcessor
CommentManager commentManager = ComponentAccessor.getCommentManager()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def subject = message.getSubject() as String
def issue = ServiceUtils.findIssueObjectInString(subject)
def body = MailUtils.getBody(message)
def sender = messageUserProcessor.getAuthorFromSender(message) as String
if (issue) {
def comment = sender + subject + " - " + body
commentManager.create(issue, reporter, comment, false)
}
If anyone has worked in this before? It would be a big help.
Thanks in advance,
Pooja