Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how I did it using the <a href="https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner" rel="nofollow">Script Runner pluging</a>, I've told Jira to get emails from my mailbox, and create issues from them. Than, on the workflow, I saved the sender's email and name to a custom fields using the following script:</p> <pre><code>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 ('&lt;' in description) and ('&gt;' in description): # pattern [Created via e-mail received from: name &lt;email@company.com&gt;] # split it to a list description_list = re.split('&lt;|&gt;|:',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) </code></pre> <p>than, send the mail using the following script:</p> <pre><code>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 + '&lt;BR&gt;' 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 = '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' html +='"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;' html +='&lt;body style="font-size:12px;font-family:Verdana"&gt;' html +='&lt;p align="center"&gt;&lt;img src="http://path/to/company_logo.jpg" alt="logo"&gt;&lt;/p&gt; ' html +='&lt;p&gt;'+htmlBody+'&lt;/p&gt;' html +='&lt;/body&gt;&lt;/html&gt;' 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('&lt;BR&gt;','\n') cm.create(issue,'anonymous','Email was sent to the customer ; Subject: '+subject+'\n'+email_body,False) </code></pre> <p>content of <code>new_case.template</code>:</p> <pre><code>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 </code></pre> <p>All scripts should be attach to the workflow, to <code>Create</code> transition.The scripts are written using <a href="http://www.jython.org/" rel="nofollow"><code>Jython</code></a>, so it needs to be installed to use it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload