Send email with custom script (groovy)

Good afternoon, I want to send an email through SMTP, it’s just an informative email; of text only I’m trying to do it by custom script but I have difficulties with the library. Could you please help me?
I attach the code used.

input = ['mail_host', 'mail_user', 'mail_password','mail_port']

def customScript() {
    javax.mail.Session session = session.getDefaultInstance(new Properties())

    javax.mail.internet.MimeMessage message = new javax.mail.internet.MimeMessage(session)
    message.setRecipient(Message.RecipientType.TO, new javax.mail.internet.InternetAddress(""))
    message.setSubject("Important message!")
    message.setText("Here is an important email message!")

    javax.mail.Transport transport = javax.mail.Session.getTransport("smtp")
    transport.connect(mail_host, mail_port, mail_user, mail_password)
    transport.sendMessage(message, message.getAllRecipients())


Hi @leydy_zapata you cannot use javax.mail in a Custom Action. You can use in “Code” perspective in the Studio if you export your recording as a bot task.

Hi, ashapkina, I do not know if you are referring to this specific task, I have seen in some forums that these plugins can be used for sending emails, but it is not clear to me how they can be used. The solution that I am looking for is to send the mail by code since we need to avoid that it is done by a series of steps that simulate said sending. Can you explain how I can use this plugin? I am new to workfusion and I still do not have this clear part. Please your help.
Thank you, stay tuned

Yes, you can use the mail plugin to send emails in RPA Express.

The plugins you can use for it are:

  • mail
  • mail-attach

Before that, you need to switch to “Code” perspective in WorkFusion Studio


and create a new bot task

Note that a bot task can be published to Control Tower and used as a step in a business process, but you cannot use it in your recordings in WF studio.

You can read more details about these plugins here