CC mail in send custom email

Fabrizio Galletti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2013

I'm trying to modify the built in script "send to custom email to accept a addresses inserted into some customfield in Email CC.

how can this be done?

in this https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions documentation he tells that i can add

Email email = newEmail("someuser@example.com") // Set the TO address, optionally CC and BCC

some more examle? someone has modified the default script ?

3 answers

1 accepted

4 votes
Answer accepted
Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2013

I had a quick peek of the API here:

http://docs.atlassian.com/jira/latest/com/atlassian/jira/mail/Email.html

The below should give you what you're after:

Email(String to)
Constructor specifying only the recipient.
Email(String to, String cc, String bcc)
Constructor including cc and bcc addresses.

Are you familiar with how to pull values from a custom field to populate the CC field?

Fabrizio Galletti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

tnks

to modify the built in script i've to hack the library then? can't i add somewhere else the script?

0 votes
Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

hmm ... it won't be as easy as changing a single line of code if you modify the built in script. You'd also need to create an input field for the CC line similar to how the TO input field exists, and who knows how you'd modify the behavior of the plug in with your changes. If you have some programming experience, I'd suggest creating a custom script. If you have none, .. well .. see if you can borrow a programmer. here's an example of a script that I use that sends emails to certain users when all tasks for a parent issue are done. Dissect and modify if you wish:

import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.mail.server.managers.OFBizMailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.jira.mail.Email
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys

log = Category.getInstance("com.onresolve.jira.groovy.TicketWatcher")
log.setLevel(org.apache.log4j.Level.WARN)
log.debug ("---- Ticket Watcher script running ----")

def sendEmail = true
issue.getParentObject().getSubTaskObjects().each { t ->
	log.debug ("Analyzing $t")
	if (!t.getStatusObject().getName().equals("Done")) { 
		sendEmail = false
		log.debug ("$t is still open.  Do not send email.")
	}
}

if (sendEmail) {
	// configure email
	def projectManager = issue.getProjectObject().getLead().emailAddress
	def baseURL = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)
	def issueURL = baseURL + "/browse/" + issue
	def parentURL = baseURL + "/browse/" + issue.getParentObject()
	log.debug ("address: $projectManager")	
	log.debug ("base URL: $baseURL")
	log.debug ("issue URL: $issueURL")
	log.debug ("parent URL: $parentURL")
	
	OFBizMailServerManager mailServerManager = componentManager.getMailServerManager()
	com.atlassian.mail.server.SMTPMailServer smtp = mailServerManager.getDefaultSMTPMailServer()
	Email email = new Email(projectManager)
	email.setFrom(smtp.getDefaultFrom())
	email.setSubject("Ticket ${issue.getParentObject()} Requires Review")
	email.setBody("The last open task (<a href=\"$issueURL\">$issue</a>) for ticket <a href=\"$parentURL\">${issue.getParentObject()}</a> was just closed.  Please review <a href=\"$parentURL\">${issue.getParentObject()}</a> to determine if it should also be closed.")
	email.setMimeType("text/html")

	// send email
	SingleMailQueueItem item = new SingleMailQueueItem(email)
	try {
		ComponentAccessor.getMailQueue().addItem(item);
	} catch (Exception e) {
		log.warn("ERROR SENDING TICKET WATCHER EMAIL", e);
	}
}
log.debug ("---- Ticket Watcher script ended ----")

Fabrizio Galletti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

i've duplicated the send email, and modified adding another fields.

the problem is that i need to rebuild the jar i suppose

0 votes
Fabrizio Galletti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

tnks

to modify the built in script i've to hack the library then? can't i add somewhere else the script?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events