CC mail in send custom email

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

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?

tnks

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

tnks

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

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 ----")

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

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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 10, 2018 in Marketplace Apps

Learn about how Stefan K. built one of the *first ever* Marketplace apps

In this post you will discover more about the evolution of K15t software, some big topics they're currently focusing on in the app space, and a rare (not not funny!) photo of founders Mike Cannon-Bro...

12,645 views 11 24
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you