简体   繁体   English

Jira Script Runner - 创建过渡的Post Function不发送邮件

[英]Jira Script Runner - Mail is not sent by Post Function of Create Transition

we have a Project in Jira which we use as an inbox for Email. 我们在Jira有一个项目,我们用它作为电子邮件的收件箱。 Not all people sending emails are users in JIRA (and they shall not be). 并非所有发送电子邮件的人都是JIRA中的用户(并且他们不会)。 Nevertheless, we would like to inform then on having received the Email. 不过,我们想通知收到电子邮件。 The emailaddress is part of the Issue description. 电子邮件地址是问题描述的一部分。

I am aware of some plugins out there but instead of replacing the Mailhandlers, I am trying to write a groovy script for JIRA adapting this code which I want to post into a Post Function on the CREATE transition of a workflow. 我知道一些插件,但不是替换Mailhandlers,我正在尝试为JIRA编写一个groovy脚本,以适应此代码 ,我想在工作流的CREATE转换中发布到Post函数中。

The following code works fine when I grab an existing Test-Issue and run the script in the console: 当我抓住现有的Test-Issue并在控制台中运行脚本时,以下代码可以正常工作:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer

ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()

if (mailServer) {
    if (true) {  

        IssueManager issueManager = componentManager.getIssueManager()    
        Issue issue = issueManager.getIssueObject("IN-376")

        def grabEmail = {
            (((it.split(   "\\[Created via e-mail received from:")[1]).split("<")[1]).split(">")[0])
        }
        String senderAddress = grabEmail("${issue.description}")

        Email email = new Email(senderAddress) 
        email.setSubject("JIRA Ticket erstellt: ${issue.summary}") 
        String content = "Content ----> by Issue2 ${issue.description}"
        email.setBody(content)
        mailServer.send(email)


    }
}

Alas, it will not run in the Post Function like this: 唉,它不会像这样在Post函数中运行:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
//import com.atlassian.jira.issue.IssueManager
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer

ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()

if (mailServer) {
    if (true) {  

        //IssueManager issueManager = componentManager.getIssueManager()    
        //Issue issue = issueManager.getIssueObject("IN-376")

        def grabEmail = {
            (((it.split(   "\\[Created via e-mail received from:")[1]).split("<")[1]).split(">")[0])
        }
        String senderAddress = grabEmail("${issue.description}")

        Email email = new Email(senderAddress) 
        email.setSubject("JIRA Ticket erstellt: ${issue.summary}") 
        String content = "Content ----> by Issue2 ${issue.description}"
        email.setBody(content)
        mailServer.send(email)


    }
}

I have no idea why the second code breaks since the code this is based on uses issue also as if it is implicitly defined. 我不知道为什么第二个代码会破坏,因为这是基于使用问题的代码,就好像它是隐式定义的一样。 This Post function is the last to run. 这个Post函数是最后运行的。

I would also find hints as to debugging this problem helpful. 我也会发现有关调试此问题的提示很有帮助。

Thank you! 谢谢!

I'll post my comment as an answer: I did not find an error in any of the logs, then. 我会发表我的评论作为答案:我没有在任何日志中找到错误,然后。 Maybe I oversaw it, sorry, but I have changed a lot of config by now (installing JEMH trial) so I can not reproduce. 也许我会监督它,抱歉,但我现在已经改变了很多配置(安装JEMH试用版)所以我无法重现。 Strangely enough, the message gets sent right now, so I have that ill feeling that I had some config in the Notifications Scheme wrong. 奇怪的是,消息现在被发送了,所以我感觉我在通知方案中有一些配置错误。

Thanks everyone for the help and time. 谢谢大家的帮助和时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM