Hey folks I need your help, I guess it is a simple question.
I use Scriptrunner to send emails to assignees and this works well. I send the email with this line of code:
sendEmail(emailAddr, emailSubject, emailBody)
But know I dont want to send it to the assignee (assignee.getEmailAddress()), I want to send it to a user, that is selected via a customfield, which is a user picker.
When I write:
def user = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(10414))
emailAddress = user.getEmailAddress()
I receive an Error because jira things of it as an object and not as an user. how can I change that?
Best
Hey @dD
You may have to try the code like this which i pulled out from here https://community.atlassian.com/t5/Jira-Software-questions/Scriptrunner-Script-Field-Custom-Email/qaq-p/1749864
import com.atlassian.mail.Email
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.customFieldManager
def mailServerManager = ComponentAccessor.mailServerManager
def mailServer = mailServerManager.defaultSMTPMailServer
def users = customFieldManager.getCustomFieldObjectsByName("<custom_field_Name>")[0]
def usersSet = issue.getCustomFieldValue(users) as Set<ApplicationUser>
usersSet.each {
def emailAddress = it.emailAddress
def subject = "Test"
def body = "This is a test message"
def email = new Email(emailAddress)
email.setSubject(subject)
email.setBody(body)
email.setMimeType("text/html")
def threadClassLoader = Thread.currentThread().contextClassLoader
Thread.currentThread().contextClassLoader = mailServer.class.classLoader
mailServer.send(email)
Thread.currentThread().contextClassLoader = threadClassLoader
}
Hope this helps !!
Regards,
Vishwas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @dD - I cam across your post and I am actually facing a very similar problem. Sending an email to a user picked in a custom field - how did you manage to resolve it as I am also getting an error and my code does not run because of that? Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.