Hello community,
I am to get comfortable with ScriptRunner and hence I want to use it in order to rebuilt my Jira-automation-Rules.
In this specific Rule I want to send (every JAN, each year) a email to certain assignees. But it is a little more complex. I want to send email to the assignees of an certain issuetype ("SUD Modul Basic"), but only if the Custom Field ("Sommersemester aktiv?") is activ. Additionally the assignee has to equal the assignee of an different issuetype ("SUD Lehrkraft"), which in this case also triggers the rule within the Scheduled-JQL.
The automation-rule works flowless but I havent got the faintest idea how I could rebuilt this with script runner. I copy+pasted a standard framework for emails in a scheduledjob, but I dont know how to further proceed.
String ISSUE_TYPE_ID = "10200"
Issue issue = event.getIssue()
if (issue.getIssueTypeId() != ISSUE_TYPE_ID) {
return
}
String sendEmail(String emailAddr, String subject, String body) {
def logger = Logger.getLogger(getClass())
logger.setLevel(Level.DEBUG)
// Stop emails being sent if the outgoing mail server gets disabled (useful if you start a script sending emails and need to stop it)
def mailSettings = ComponentAccessor.getComponent(MailSettings)
if (mailSettings?.send()?.disabled) {
return 'Your outgoing mail server has been disabled'
}
def mailServer = ComponentAccessor.mailServerManager.defaultSMTPMailServer
if (!mailServer) {
logger.debug('Your mail server Object is Null, make sure to set the SMTP Mail Server Settings Correctly on your Server')
return 'Failed to Send Mail. No SMTP Mail Server Defined'
}
def email = new Email(emailAddr)
email.setMimeType('text/html')
email.setSubject(subject)
email.setBody(body)
try {
// This is needed to avoid the exception about IMAPProvider
ContextClassLoaderSwitchingUtil.runInContext(SMTPMailServer.classLoader) {
mailServer.send(email)
}
logger.debug('Mail sent')
'Success'
} catch (MailException e) {
logger.debug("Send mail failed with error: ${e.message}")
'Failed to Send Mail, Check Logs for error'
}
}
sendEmail('user@email.com', '<Your subject here>', '<Your body here>')
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.