Write a Groovy script to send an email notification if a test case fails.

Groovy scripts in SOAP UI can send email notifications when a test case fails, useful for automated testing environments.

Here’s an example script :
import javax.mail.*
import javax.mail.internet.*
def sendEmail(subject, body) {
    def props = new Properties()
    props.put("mail.smtp.host", "smtp.example.com")
    props.put("mail.smtp.port", "587")
    props.put("mail.smtp.auth", "true")
    props.put("mail.smtp.starttls.enable", "true")
    def session = Session.getInstance(props, new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("your_email@example.com", "your_password")
        }
    })
    try {
        def message = new MimeMessage(session)
        message.setFrom(new InternetAddress("your_email@example.com"))
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient@example.com"))
        message.setSubject(subject)
        message.setText(body)
        Transport.send(message)
        log.info "Email sent successfully"
    } catch (MessagingException e) {
        log.error "Failed to send email: " + e.message
    }
}
if (testRunner.status == com.eviware.soapui.model.testsuite.TestRunner.Status.FAILED) {
    sendEmail("Test Case Failed", "The test case ${testRunner.testCase.name} has failed.")
}?