How do you send an email through ScriptRunner using Groovy?

Kyle Moseley _blueridge_cx_ September 19, 2014

I've tried the following code and had no luck. Does anyone have a simple script or any guidance?

 

import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
subject = "test"
body = "test"
emailAddr = "email@whatever.com"

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
  }
}

1 answer

1 accepted

3 votes
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.
September 19, 2014

You're missing the line like:

sendEmail (emailAddr, subject, body) 

 

 

Kyle Moseley _blueridge_cx_ September 19, 2014

Adding "import com.atlassian.jira.ComponentManager" and actually calling sendMail did the trick. Thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events