Skip to main content
Example scripts
arrow icon
To homepage
Confluence
Cloud icon
Cloud

Send email notification from a custom script in Confluence.

Created 9 month(s) ago, Updated 1 day(s) ago
App in script
ScriptRunner For Confluence
ScriptRunner For Confluence
by Adaptavist
Compatibility
compatibility bullet
Confluence
Language |
groovy
import javax.mail.internet.*
import javax.mail.*

Properties prop = new Properties()
//Enter the details of your SMTP server
prop.put("mail.smtp.auth", true)
prop.put("mail.smtp.host", "smtp.gmail.com")
prop.put("mail.smtp.port", "450")
prop.put("mail.smtp.starttls.enable", "true")

String emailId = "<email id>"
String password = "<password>"

Session session = Session.getInstance(prop, new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        new PasswordAuthentication(emailId, password)
    }
})

MimeMessage msg = new MimeMessage(session)
msg.setFrom(new InternetAddress(emailId, "NoReply-JD"))
msg.setSubject("<Test email>", "UTF-8")
msg.setText("<Test body>", "UTF-8")
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailId, false))

Transport.send(msg)
logger.info("Email Sent Successfully!!")
Having an issue with this script?
Report it here