Sending mail via script

Hi everyone,

I am trying to send an email inside my test case using Send email using groovy script · GitHub I downloaded the Jar and it looks like there is no error but I get: “There are errors in the script. Please fix before executing”.

The only code in my test case is Send email using groovy script · GitHub

Any ideas?

Can you please share your exact script from katalon - also if there are errors in the script it should give you a little red cross on the line causing this error

Here is my script. There are no red lines (or black lines)

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

Get Any JAVAMAIL Dependency
Download JAVAMAIL dependency that you need.
download JAVAMAIL at :
To install, copy & paste the *.jar to installed Groovy lib directory:
eg: C:\Program Files (x86)\Groovy\Groovy-2.1.1\lib

public class SMTPAuthenticator extends Authenticator
	public PasswordAuthentication getPasswordAuthentication()
		return new PasswordAuthentication('my mail', 'my password');

def  d_email = "my mail",
	 d_uname = "my mail",
	 d_password = "my password",
	 d_host = "",
	 d_port  = "465", //465,587
	 m_to = "some other mail",
	 m_subject = "Testing",
	 m_text = "Hey, this is the testing email."

def props = new Properties()
props.put("mail.smtp.user", d_email)
props.put("", d_host)
props.put("mail.smtp.port", d_port)
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.auth", "true")
props.put("mail.smtp.socketFactory.port", d_port)
props.put("mail.smtp.socketFactory.class", "")
props.put("mail.smtp.socketFactory.fallback", "false")

def auth = new SMTPAuthenticator()
def session = Session.getInstance(props, auth)

def msg = new MimeMessage(session)
msg.setFrom(new InternetAddress(d_email))
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to))

Transport transport = session.getTransport("smtps");
transport.connect(d_host, d_port, d_uname, d_password);
transport.sendMessage(msg, msg.getAllRecipients());

Let me know if you want to use an alternative solution with less moving parts.

Yeah I will love to see, I just took this to see how to send a mail.


@Russ_Thomas and @hpulsford I saw that there is not support for:

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


import javax.activation.DataHandler
import com.sun.mail.util.MailLogger
import javax.activation.FileDataSource
import javax.mail.Message
import javax.mail.MessagingException
import javax.mail.Multipart
import javax.mail.Session
import javax.mail.Transport
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeBodyPart
import javax.mail.internet.MimeMessage
import javax.mail.internet.MimeMultipart

does work… I am still getting a problem that SMTPAuthenticator is not recognized. Do you know why?

No. When I first started using Katalon (Feb 2018) I had problems with the inbuilt email. I stopped trying and used what I’ve already shown you.