【问题标题】:JIRA - Send email to anonymous userJIRA - 向匿名用户发送电子邮件
【发布时间】:2011-09-29 20:59:54
【问题描述】:

当有人通过电子邮件创建问题时,我正在尝试找出一种向匿名用户发送电子邮件的方法。我需要的是让这个匿名用户在问题被打开、评论和关闭时收到一封通知电子邮件。 根据他们的official documentation,只有在创建者已经是 JIRA 中的用户或者将动态创建用户时才能这样做。这些都不适合我。 到目前为止,我发现的解决方法是:

  1. JEMH - 承诺此功能但看起来不稳定,这意味着它似乎会随着每次 JIRA 更新而中断(至少有一点),而且我无法接受停机时间。
  2. 按照similar thread 中的建议编写我自己的脚本

我编写自己的脚本没有问题,但我只是想确定我不会重新发明轮子。有没有其他方法可以做到这一点?

如果能提供任何帮助,我将不胜感激。

【问题讨论】:

  • “我不能接受停机时间”。确定在 JEMH 插件更新之前不需要升级?
  • 我明白你在说什么,mdoar,我明白你的意思。然而,JEMH 至少从外观上看是由一个人开发的,如果他决定不再支持他的项目,我将被“无法升级”的 JIRA 困住,并且不得不再次寻找替代品。

标签: notifications jira issue-tracking


【解决方案1】:

我刚刚注意到这个问题。 JEMH 现在已经发展成为一个成熟的商业插件,并拥有大量新功能,其中一些实际上解决了支持远程“匿名”用户创建问题的问题,基本上将 JIRA 变成了一个功能齐全的电子邮件帮助台解决方案。可以针对每个事件进行特定的模板自定义。

关于损坏,保持“最新”版本让开发人员完全没有时间追赶。玩得聪明,给所有开发者一个追赶的机会。

随着 JEMH 深入研究 JIRA API 的深度,不幸的是,损坏很常见,但现在由于 Atlassian 在 5.0+ 中稳定了一些核心 API,损坏的可能性降低了。提供端端集成测试的工作也在进行中,这本身就是一项使命!

【讨论】:

    【解决方案2】:

    这是我使用Script Runner pluging 的方法,我告诉 Jira 从我的邮箱中获取电子邮件,并从中创建问题。然后,在工作流程中,我使用以下脚本将发件人的电子邮件和姓名保存到自定义字段中:

    from com.atlassian.jira import ComponentManager
    import re
    cfm = ComponentManager.getInstance().getCustomFieldManager()
    
    # read issue description
    description = issue.getDescription()
    if (description is not None) and ('Created via e-mail received from' in description):
        # extract email and name:
        if ('<' in description) and ('>' in description):
            # pattern [Created via e-mail received from: name <email@company.com>]
            # split it to a list
            description_list = re.split('<|>|:',description)
            list_length = len(description_list)
            for index in range(list_length-1, -1, -1):
                if '@' in description_list[index]:
                    customer_email = description_list[index]
                    customer_name = description_list[index - 1]
                    break
        else:
            # pattern [Created via e-mail received from: email@company.com]
            customer_name = "Sir or Madam"
            # split it to a list  
            description_list = re.split(': |]',description)
            list_length = len(description_list)
            for index in range(list_length-1, -1, -1):
                if '@' in description_list[index]:
                    customer_email = description_list[index]
                    break
    
        # if the name isn't in the right form, switch it's places:
        if (customer_name[0] == '"') and (customer_name[-1] == '"') and (',' in customer_name):
            customer_name = customer_name[1:-1]
            i =  customer_name.index(',')
            customer_name = customer_name[i+2:]+" "+customer_name[:i]
    
        # insert data to issue fields
        issue.setCustomFieldValue(cfm.getCustomFieldObject("customfield_10401"),customer_email)
        issue.setCustomFieldValue(cfm.getCustomFieldObject("customfield_10108"),customer_name)
    

    然后,使用以下脚本发送邮件:

    import smtplib,email
    from smtplib import SMTP 
    from email.MIMEMultipart import MIMEMultipart
    from email.MIMEBase import MIMEBase
    from email.MIMEText import MIMEText
    from email import Encoders
    import os
    import re
    from com.atlassian.jira import ComponentManager
    
    customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
    cfm = ComponentManager.getInstance().getCustomFieldManager()
    
    # read needed fields from the issue
    key = issue.getKey()
    #status = issue.getStatusObject().name
    summary = issue.getSummary()
    project = issue.getProjectObject().name
    
    # read customer email address
    toAddr = issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_10401"))
    # send mail only if a valid email was entered
    if (toAddr is not None) and (re.match('[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,4}',toAddr)):
        # read customer name
        customerName = issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_10108"))
        # read template from the disk
        template_file = 'new_case.template'
        f = open(template_file, 'r')
        htmlBody = ""
        for line in f:
            line = line.replace('$$CUSTOMER_NAME',customerName)
            line = line.replace('$$KEY',key)
            line = line.replace('$$PROJECT',project)
            line = line.replace('$$SUMMARY',summary)
            htmlBody += line + '<BR>'
    
    
        smtpserver = 'smtpserver.com'
        to = [toAddr]
        fromAddr = 'jira@email.com'
        subject = "["+key+"] Thank You for Contacting Support team"
        mail_user = 'jira@email.com'
        mail_password = 'password'
    
        # create html email
        html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
        html +='"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">'
        html +='<body style="font-size:12px;font-family:Verdana">'
        html +='<p align="center"><img src="http://path/to/company_logo.jpg" alt="logo"></p> '
        html +='<p>'+htmlBody+'</p>'
        html +='</body></html>'
    
        emailMsg = email.MIMEMultipart.MIMEMultipart('alternative')
        emailMsg['Subject'] = subject
        emailMsg['From'] = fromAddr
        emailMsg['To'] = ', '.join(to)
        emailMsg.attach(email.mime.text.MIMEText(html,'html'))
    
        # Send the email
        s = SMTP(smtpserver) # ip or domain name of smtp server
        s.login(mail_user, mail_password)   
        s.sendmail(fromAddr, [to], emailMsg.as_string())
        s.quit()
    
        # add sent mail to comments
        cm = ComponentManager.getInstance().getCommentManager()
        email_body = htmlBody.replace('<BR>','\n')
        cm.create(issue,'anonymous','Email was sent to the customer ; Subject: '+subject+'\n'+email_body,False)
    

    new_case.template的内容:

    Dear $$CUSTOMER_NAME,
    
    Thank you for contacting support team.
    
    We will address your case as soon as possible and respond with a solution very quickly.
    
    Issue key $$KEY has been created as a reference for future correspondence.
    
    If you need urgent support please refer to our Frequently Asked Questions page at http://www.example.com/faq.
    
    Thank you,
    
    Support Team
    
    
    Issue key: $$KEY
    Issue subject: $$PROJECT
    Issue summary: $$SUMMARY
    

    所有脚本都应附加到工作流,Create 转换。脚本是使用Jython 编写的,因此需要安装才能使用它。

    【讨论】:

      【解决方案3】:

      我怀疑这个功能是否已经内置到 JIRA 中,我还没有看到可以做到这一点的插件。

      我过去研究过这个,结果一无所获。我怀疑它不是内置的,因为对于许多潜在客户来说,它可以让他们摆脱 10 个用户的许可证,但仍然支持数千个用户。

      我们改为使用无限制用户许可证。

      更新:我想补充一点,您可以编写一个脚本来执行此操作。但它看起来像是一个 PITA,必须为其创建一个自定义侦听器来捕获对问题的更改https://developer.atlassian.com/display/DOCS/Plugin+Tutorial+-+Writing+event+listeners+with+the+atlassian-event+library

      【讨论】:

      • 谢谢 Jason,这看起来很有希望。我会调查一下。
      【解决方案4】:

      您可以使用 Raley Email Notifications 向存储在 Jira 自定义字段中的电子邮件发送通知 配置很简单,下面是一个示例: https://wiki.raleyapps.com/display/RAL/Sending+email+to+value+from+JIRA+issue+custom+field

      【讨论】:

        猜你喜欢
        • 2012-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-21
        • 1970-01-01
        • 1970-01-01
        • 2019-12-15
        相关资源
        最近更新 更多