How to add email addresses in SendCustomEmail

Alexander January 20, 2015

Hello everyone!
I'm using script runner and "Send a custom email" listener.I want to add (automatically) emails in "" field.
I think, the solution is to use custom groovy script which can call this listener and add emails in that field.
I have some questions:
How can I call this listener? and How can I add emails in that field?

Sorry for my bad language.
Any help would be greatly appreciated!

2 answers

1 accepted

1 vote
Answer accepted
JamieA
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.
January 21, 2015

If you want to dynamically change the recipients, you should send it to the value of a user or multiuser custom field, and you set the value of that to a user or list of users.

So "To Addresses" is for email addresses, "To Fields" is for using fields to govern the recipients.

Alexander January 21, 2015

Hi Jamie, thanks for the answer. Can you provide some guidance how to do it better? I tried to get watchers: watcherManager.getCurrentWatcherUsernames(issue); and then get email addresses via watcherUser.getEmailAddress(); It works, but it only a half of work:) How can I add these email addresses? Explain me please. I also tried to create some custom groovy for sending email: Email email = new Email(emailTo); email.setSubject(subject); email.setBody(content); mailServer.send(email); But I don't know how to add files like your "Send a custom email" listener.

Alexander January 21, 2015

I understood all. thank you. Solved.

MK February 22, 2021

I have below under condition and configuration for send a custom email which is working okay. Now If I include Geo channel the script will be lengthy and will cause performance issue. How can I use geo channel along with product and keep the script short and simple to make sure there is no performance issue. Kindly suggest!


{code:java}
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager

def plugin = ComponentAccessor.getPluginAccessor().getPlugin("com.valiantys.jira.plugins.SQLFeed")
def serviceClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldDisplayService")
def fieldDisplayService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceClass)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//issueKey
def key = issue.getKey()
//get H24 product(Product name)
def product_string = fieldDisplayService.getDisplayResult(issue.getKey(), "customfield_20812")
def String product_stringValue = (product_string != null ? product_string.getDisplay() : '')
//SF Account

//Account name?
def account_String = fieldDisplayService.getDisplayResult(issue.getKey(), "customfield_28808")
def String account_StringValue = (account_String != null ? account_String.getDisplay() : '')
//case number?
def caseNumber = customFieldManager.getCustomFieldObjectByName("Case Number")
def caseNumberFieldValue = issue.getCustomFieldValue(caseNumber)
//customer contact name?
def contactName_String = fieldDisplayService.getDisplayResult(issue.getKey(), "customfield_20908")
def String contactNameValue = (contactName_String != null ? contactName_String.getDisplay() : '')
//Date (issue created)?
def issueCreate = issue.getCreated()
//case subject(summary)?
def summary = issue.getSummary()
//customer impact?
def customrImpact = customFieldManager.getCustomFieldObjectByName("Customer Impact")
def customrImpactFieldVaue = issue.getCustomFieldValue(customrImpact)
//customer impact notes?
def customrImpactNotes = customFieldManager.getCustomFieldObjectByName("Customer Impact Notes")
def customrImpactNotesFieldVaue = issue.getCustomFieldValue(customrImpactNotes)
//case description?
def description = issue.getDescription()
//Last comment
def comment = ComponentAccessor.getCommentManager().getLastComment(issue).getBody()

//Geo channel
def geoChannel = fieldDisplayService.getDisplayResult(issue.getKey(), "customfield_27009")
def String geoChannelValue = (geoChannel != null ? geoChannel.getDisplay() : '')
//Email Subject
def emailSubject = "UPDATE: $product_stringValue Priority 1 for $account_StringValue"
//Email Template(Body)
def String emailBody = "***For internal use only and not for further dissemination.***\n \nThis email is to inform you of a $product_stringValue Priority 1 Case for $account_StringValue Case $caseNumberFieldValue. \n$contactNameValue contacted HELP24 on $issueCreate to report a priority 1 situation occurring on $product_stringValue. \n\nCase Subject: \n$summary \n\nCustomer Impact: $customrImpactFieldVaue \n\n$customrImpactNotesFieldVaue \n\nCase Description: \n$description \n\nUpdates: \n$comment \n\nThe HELP24 team is currently investigating this issue and will provide regular updates directly to the customer. Updates on this P1 case will follow until the case is resolved. \n\n\nRegards, \nThe Global HELP24 Team\n$caseNumberFieldValue \nhttps://gojira.am.tsacorp.com/browse/$key"

mail.setBody(emailBody)
mail.setSubject(emailSubject)

if (product_stringValue == "BASE24") {
mail.setTo("grpexamplehp24-P1-Product-B24@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "BASE24-eps") {
mail.setTo("grpexamplehp24-P1-Product-B24-eps@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Commerce Gateway") {
mail.setTo("grpexamplehp24-P1-product-cg@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "COMMS") {
mail.setTo("grpexamplehp24-P1-Product-COMMS@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Enterprise Banker") {
mail.setTo("grpexamplehp24-P1-Product-EB@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Global Trade Manager") {
mail.setTo("grpexamplehp24-P1-Product-GTM@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "GoldenGate") {
mail.setTo("grpexamplehp24-P1-Product-GG@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "ISD") {
mail.setTo("grpexamplehp24-P1-Product-ISD@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Mobile Channel Manager") {
mail.setTo("grpexamplehp24-P1-Product-MCM@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "MTS") {
mail.setTo("grpexamplehp24-P1-Product-MTS@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "NETWORK SYSTEMS") {
mail.setTo("grpexamplehp24-P1-Product-XPNET@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "OCM24") {
mail.setTo("grpexamplehp24-P1-Product-OCM24-iExchange@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "iExchange") {
mail.setTo("grpexamplehp24-P1-Product-OCM24-iExchange@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Online Banking") {
mail.setTo("grpexamplehp24-P1-Product-OLB@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Payments Management") {
mail.setTo("grpexamplehp24-P1-Product-PM@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Postilion") {
mail.setTo("grpexamplehp24-P1-Product-Postilion@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "PRISM") {
mail.setTo("grpexamplehp24-p1-product-prism@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "PRM") {
mail.setTo("grpexamplehp24-P1-Product-PRM@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "RCS") {
mail.setTo("grpexamplehp24-P1-Product-RCS@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Token Management") {
mail.setTo("grpexamplehp24-P1-Product-TM@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Universal Online Banker") {
mail.setTo("grpexamplehp24-P1-Product-UOB@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Corporate Banking") {
mail.setTo("grpexamplehp24-P1-Product-UOB@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Universal Payments Platform") {
mail.setTo("grpexamplehp24-P1-Product-UPF@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "UP Immediate Payments") {
mail.setTo("grpexamplehp24-P1-Product-IP@email.com,grpexamplehp24-p1-updt-notifications@email.com")
} else if (product_stringValue == "Issuer" || product_stringValue == "Acquirer" || product_stringValue == "CardLinK" || product_stringValue == "Interchange" || product_stringValue == "OM - Open Messaging") {
mail.setTo("grpexamplehp24-P1-Product-CMM@email.com,grpexamplehp24-p1-updt-notifications@email.com")
}
{code}

0 votes
Alexander January 20, 2015

or I need a custom listener with the same functions: add attachments and html format.

Suggest an answer

Log in or Sign up to answer