Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner Groovy email not received

AbrahamA
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.
July 23, 2018

Hello

 

Trying to send email from Groovy in Jira7.4.4 (running from Scriptrunner console)

 

import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.INFO)
log.info "AutoEmail error log"

import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.component.ComponentAccessor;

 

def subject = "xxxxxxxxxx"
def body = "yyyyyyyyyyy"
def emailAddr = "ttt.k@ppp.com"


log.info("Email sent0")
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
log.info(mailServer)
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body);
mailServer.send(email);
log.info("Email sent")
} else {
// Problem getting the mail server from JIRA configuration, log this error
log.debug("Email error")
}

 

 

My logs show

2018-07-23 12:07:06,082 INFO [jira.groovy]: AutoEmail error log

2018-07-23 12:07:06,082 INFO [jira.groovy]: Email sent0 2018-07-23 12:07:06,083 INFO [jira.groovy]: com.atlassian.mail.server.managers.EventAwareSMTPMailServer@2a2f6339[id=10000,name=APL SMTP Server,description=,server name=gpuer.gptu.xxxx.com,username=<null>,password=<null>,isSessionServer=false,defaultFrom=apl-jira@xxxx.com,prefix=[JIRA],smtpPort=25]

2018-07-23 12:07:06,091 INFO [jira.groovy]: Email sent

 

 

But I don't get any email.

Can you please let me know.

 

Thanks

Abe

 

1 answer

1 accepted

0 votes
Answer accepted
Mark Markov
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.
July 23, 2018

Hello @AbrahamA

You code seems good, try to log email variable. And try to send email via mail queue and check how it goes at https://jira_url/secure/admin/MailQueueAdmin!default.jspa

import com.atlassian.mail.queue.SingleMailQueueItem
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.INFO)
log.info "AutoEmail error log"

import com.atlassian.mail.Email;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.component.ComponentAccessor;



def subject = "xxxxxxxxxx"
def body = "yyyyyyyyyyy"
def emailAddr = "ttt.k@ppp.com"


log.info("Email sent0")
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
log.info(mailServer)
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body);
//mailServer.send(email);
log.info("email"+email)
SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.getMailQueue().addItem(item)
log.info("Email sent")
} else {
// Problem getting the mail server from JIRA configuration, log this error
log.debug("Email error")
}

also check atlassian-jira-outgoing-mail.log for some errors

AbrahamA
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.
July 23, 2018

Thanks a lot

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events