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