Dear Jenkins users,Is there a way to send an e-mail from Jenkins Master using a Groovy script ?
I have an error which I don't know how to solve it:
FATAL: javax.mail.MessagingException: Unknown SMTP host: my.mail.host;
nested exception is:
java.net.UnknownHostException: my.mail.host
java.net.UnknownHostException: my.mail.host
The groovy script:
import javax.mail.*
import javax.mail.internet.*
def sendMail(host, sender, receivers, subject, text) {
Properties props = System.getProperties()
props.put("mail.smtp.host", host)
Session session = Session.getDefaultInstance(props, null)
MimeMessage message = new MimeMessage(session)
message.setFrom(new InternetAddress(sender))
receivers.split(',').each {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(it))
}
message.setSubject(subject)
message.setText(text)
println 'Sending mail to ' + receivers + '.'
Transport.send(message)
println 'Mail sent.'
}
Thank you,
Vlad