Hello
We would like to send a reminder to only the reporters of issues with status "Under Review" which haven't been updated for a week.
I then used the built-in script escalation service and tried to insert the following example I've found here on Answers, also applied the edits from the comments of said topic (topic) and other stuff.
import com.atlassian.mail.Email; import com.atlassian.mail.server.MailServerManager; import com.atlassian.mail.server.SMTPMailServer; import com.atlassian.jira.ComponentManager; subject = "test" body = "test" emailAddr = issue.getReporter().getEmailAddress() def sendEmail(emailAddr, subject, body) { SMTPMailServer mailServer = ComponentManager.getInstance().getMailServerManager().getDefaultSMTPMailServer(); if (mailServer) { Email email = new Email(emailAddr); email.setSubject(subject); email.setBody(body); mailServer.send(email); } else { // Problem getting the mail server from JIRA configuration, log this error } } sendEmail (emailAddr, subject, body)
However, ScriptRunner indicates that getMailServerManager can't be found and multiple other errors. When I checked the API of our current JIRA version, the desired class is actually not available anymore it seems or I just can't find it.
screenshot1.png
I then created my own version like so.
import com.atlassian.mail.Email; import com.atlassian.mail.server.MailServerManager; import com.atlassian.mail.server.SMTPMailServer; import com.atlassian.jira.functest.framework.admin; def subject = "test" def body = "test" def emailAddr = issue.getReporter().getEmailAddress() def sendEmail(emailAddr, subject, body) { SMTPMailServer mailServer = admin.MailServerAdministration.MailServerConfiguration.get() if (mailServer) { Email email = new Email(emailAddr); email.setSubject(subject); email.setBody(body); mailServer.send(email); } else { // Problem getting the mail server from JIRA configuration, log this error } } sendEmail (emailAddr, subject, body)
But this indicates that the class com.atlassian.jira.functest.framework.admin can't be resolved which I've found in the API documentation for JIRA 7.1.4
screenshot2.png
Can somebody help me here?
Thanks
Hi there,
You said you are in a JIRA v7.* , so the ComponentManager is deprecated and you should use the ComponentAccessor instead. therefore in the first script you posted you will be able to get the mailServerManager (and then the SMTPServer) like
import com.atlassian.jira.component.ComponentAccessor def mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
regards
thanos
Hi Thanos
Thanks. This works so far.
But now it says it can't find a matching method for
new Email(emailAddr);
I just checked the API again and this class and method are available in 7.1.4 and the syntax seems correct.
Any ideas?
Thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The 'errors' you see in the script runner are because of the Static Type Checking, in a dynamically-typed language. Therefore some times is safe to ignore them. So if you declare the type of your params
def sendEmail(String emailAddr, String subject, String body) { ... }
you will see the difference.
regards
Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist] ,
I try using this code, without success:
Got errors:
2018-10-09 08:22:53,337 WARN [runner.ScriptRunnerImpl]: Please make sure that a valid mailServer is configured 2018-10-09 08:22:53,337 WARN [runner.ScriptRunnerImpl]: java.lang.NullPointerException: Cannot invoke method send() on null object
My code:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import com.atlassian.jira.issue.issuetype.IssueType
import javax.ws.rs.core.Response
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.config.IssueTypeManager;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequest;
try {
sendEmail('daniel_mor@bmc.com','Mail','Hi');
}
catch (e) {
}
// Create an email
def sendEmail(String emailAddr, String subject, String body) {
//MailServerManager mailServerManager = ComponentAccessor.getMailServerManager();
def mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
//if (mailServer) {
try{
Email email = new Email(emailAddr)
email.setSubject(subject)
email.setBody(body)
mailServer.send(email)
log.debug("Mail sent")
} catch(Exception e) {
log.warn("Please make sure that a valid mailServer is configured")
log.warn e;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
Well the logs give you a hint
Please make sure that a valid mailServer is configured
Configuring an SMTP mail server
Regards, Thanos
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.