Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Working with Script mail handler

Hello Community,

I am currently writing a script for using the script mail handler for achieving the following use case.

  1. We are already using script runner for sending out email to non jira users.
  2. 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

1 answer

You can get external reporter identity using following code:

// get email sender
def reporterEmail = ""
final List<String> senders = MailUtils.getSenders(message);
for (final String emailAddress : senders)
{
   reporterEmail = emailAddress
}

 

However, use default user to create issues for non jira users. That will help to reduce number of licenses. 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you