Hello,
I have a Groovy script executed as a post-function on the Create Issue transition, which is supposed to send a mail to the reporter if certain condition is met. When I create issue from the normal JIRA Create button, it works fine. When I create the issue from the Service Desk customer portal though (JIRA Service Desk version is 2.2), it does not work and in the atlassian-jira.log I get the following exception:
javax.script.ScriptException: javax.script.ScriptException: java.lang.ClassCastException: com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler
at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runFileAsScript(ScriptRunnerImpl.groovy:194)
at com.onresolve.scriptrunner.runner.ScriptRunner$runFileAsScript$8.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:47)
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate$doScript$11.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction.doScript(CustomScriptFunction.groovy:20)
Caused by: javax.script.ScriptException: java.lang.ClassCastException: com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler
... 5 more
Caused by: java.lang.ClassCastException: com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1121)
at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendWithMessageId(SMTPMailServerImpl.java:175)
at com.atlassian.mail.server.impl.SMTPMailServerImpl.send(SMTPMailServerImpl.java:150)
at Script18.run(Script18.groovy:74)
... 5 more
Here is the Groovy script I execute:
if (totalAmount >= 500) { // Setup mail server MailServerManager mailServerManager = componentManager.getMailServerManager(); SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer(); reporter = userUtil.getUserByName(someIssue.reporter.name); reporterEmail = reporter.getEmailAddress(); reporterFirstName = reporter.displayName; if (mailServer) { Email email = new Email(reporterEmail); email.setSubject("Monthly limit exceeded"); email.setFrom("IT Support <some@mail.com>"); String content = """\ Hello ${reporterFirstName}, Your purchase request is exceeding the monthly limit. Your total purchases this month are ${totalAmount}. IT Help Desk """; email.setBody(content) mailServer.send(email) } else { log.error "[Send Survey Cron] No SMTP mail server defined."; } }
Obviously there is some difference in the way issues are created from JIRA and from Service Desk, but I have no idea where is the problem here. Any help is much appreciated!
Community moderators have prevented the ability to post new answers.
Well, I changed the way the e-mail is sent and that fixed the problem. I switched to using the Mail Queue, here is the code:
if (totalAmount >= 500) { // Setup mail server SMTPMailServer mailServer = MailFactory.getServerManager().getDefaultSMTPMailServer(); reporter = userUtil.getUserByName(someIssue.reporter.name); reporterEmail = reporter.getEmailAddress(); reporterFirstName = reporter.displayName; if (mailServer) { Email email = new Email(reporterEmail); email.setSubject("Monthly limit exceeded"); email.setFrom("IT Support <some@mail.com>"); email.setMimeType("text/html"); String content = """\ Hello ${reporterFirstName}, Your purchase request is exceeding the monthly limit. Your total purchases this month are ${totalAmount}. IT Help Desk some@mail.com """; email.setBody(content) SingleMailQueueItem item = new SingleMailQueueItem(email) ComponentAccessor.getMailQueue().addItem(item); } else { log.error "[Send Survey Cron] No SMTP mail server defined."; } }
Glad you found a way. Using the mail queue is more reliable anyway.
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.