Forums

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

Send an SMTP mail from JIRA Cloud

B. Normann P. Nielsen
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.
March 12, 2020

I need to send a SMTP mail (not a notification) from JIRA Cloud via a Script Listener.

 

Seems quite hard - I guess getting the SMTP details from JIRA is not possible.

import javax.mail.*

import javax.mail.internet.*

 

does not seem enough...

 

import javax.mail.internet.*
import javax.mail.*

def iaChange = changelog?.items.find { it['field'] == 'Incident Attention' }

if (!iaChange) {
logger.info("Incident Attention was not updated")
return;
}
logger.info("Incident Attention changed from {} to {}", iaChange.fromString, iaChange.toString)
if (iaChange.toString.contains("Security Risk")) {

// Set up properties.
Properties props = System.getProperties()
props.put("mail.smtp.user", "ds@mserver.dk")
props.put("mail.smtp.host", "relay.server.dk")
props.put("mail.smtp.port", 587)
props.put("mail.smtp.starttls.enable","true")
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory")
props.put("mail.smtp.ssl.trust", "*") // Change host to "*" if you want to trust all host.

// Set up message.
MimeMessage message = new MimeMessage(Session.getDefaultInstance(props))
message.setFrom(new InternetAddress(addresser))
message.addRecipients(Message.RecipientType.TO, new InternetAddress("npn@server.dk"))
message.setSubject("test mail")
message.setContent("Test content", 'text/html;charset=utf-8')

try
{
Transport.send(message, "ds@server.dk", "password")
logger.info "Mail was sent to ds@server.dk"
}
catch (Exception ex)
{
logger.info "Mail send failed: " + ex.getMessage()
}
}

 

Errors:

 

2020-03-12 08:20:02.598 ERROR - startup failed:
Script1.groovy: 23: unable to resolve class MimeMessage 
 @ line 23, column 17.
       MimeMessage message = new MimeMessage(Session.getDefaultInstance(props))
                   ^

Script1.groovy: 23: unable to resolve class MimeMessage 
 @ line 23, column 27.
       MimeMessage message = new MimeMessage(Session.getDefaultInstance(props))
                             ^

Script1.groovy: 24: unable to resolve class InternetAddress 
 @ line 24, column 21.
       message.setFrom(new InternetAddress(addresser))
                       ^

Script1.groovy: 25: unable to resolve class InternetAddress 
 @ line 25, column 53.
   nts(Message.RecipientType.TO, new Intern

 

1 answer

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 16, 2020

Hi Norman,

Thank you for your question.

I can confirm that it is not possible to get the SMTP details from Jira Cloud and to send an SMTP email with ScriptRunner for Jira Cloud.

The reason for this is that Atlassian does not provide a rest API to access the SMTP details and that ScriptRunner for Jira Cloud can only use the public rest API's which Atlassian provide and allow apps to use.

The only API to send an email provided is the notify API and I can confirm we have an example of how this works located here.

I hope this information helps.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events