[Updated 2022-06-14] How to send arbitrary emails from Katalon/Groovy Script

Download:

website: http://freshmeat.sourceforge.net/projects/sendemail/

Create a batch file with your command string:

@echo %DATE% %TIME%

c:\dl\sendemail\sendemail -f me@example.com -t you@example.com me@example.com -u %3 -s example-mail.server.com:587 -xu me@example.com -xp "password" -o tls=yes -o message-content-type=html -o message-file=%1 -a %2

Where

  • %1 is the message
  • %2 is an attachment (screenshot perhaps)
  • %3 is the subject line
  • See the documentation for the other options available

Create a sendEmail keyword in Katalon:

  /**
   * Sends the report in an email.
   * @param subjectLine (String) The subject line of the email.
   * @param reportFileName (String) The report file to be sent.
   */
  static void sendEmail(String subjectLine, String reportFileName) {
    String screenShot = getScreenshotPath()
    WebUI.takeScreenshot(screenShot)
    String emailParams = '"' + reportFileName + '" ' +
        '"' + screenShot + '" ' +
        '"' + subjectLine + '"'
    comment('Sending email : ' + emailParams)
    runBatchFile('sender.bat ' + emailParams + ' >> sender-log.txt')
  }

And another keyword for runBatchFile:

  /**
   * Execute a batch file situated in the KS project directory.
   * @param batchFile (String) e.g. "myfile.bat"
   */
  static void runBatchFile(String batchFile) {
    String bf = RunConfiguration.getProjectDir() + '/' + batchFile
    comment("Running batch file: " + bf)
    Runtime.runtime.exec(bf)
  }
5 Likes

@Russ_Thomas heeey, don’t encourage spammers :)) with great scripts come greater responsabilities :))
i like the solution, shushh

2 Likes

Updated OP with new links.

1 Like