KRE - Setup Email as part of CI/CD Azure

Katalon Studio support send email feature as part of the Test Suite. But when running the tests in Azure Cloud, there is no way to configure Email.

Running tests on Azure Cloud is using online license and fresh installation of Katalon Studio each time.

Is there a way to setup email during a fresh installation using any command line tool? There is a -sendEmail functionality for command line but there is no way to configure it unless user can access Katalon Studio.

When running on cloud, user cannot access Katalon studio UI.

1 Like

To configure email notifications in Katalon Studio when running tests on Azure Cloud (without UI access), use a command-line-driven approach with preconfigured settings. Here’s how:

1. Use katalon-config.properties for Email Settings

Create a katalon-config.properties file in your project with placeholders for Azure variables:

# Email Settings
notification.email.enabled=true
notification.email.smtp.host=${SMTP_HOST}
notification.email.smtp.port=${SMTP_PORT}
notification.email.smtp.username=${SMTP_USER}
notification.email.smtp.password=${SMTP_PASSWORD}
notification.email.sender=${SENDER_EMAIL}
notification.email.recipients=${RECIPIENTS}
notification.email.subject=Azure Test Report
notification.email.body=Test execution completed. Attached is the report.
notification.email.attachReport=true

2. Inject Azure Pipeline Variables

In your azure-pipelines.yml, define variables (including secrets):

variables:
  SMTP_HOST: 'smtp.office365.com'
  SMTP_PORT: '587'
  SMTP_USER: 'your-email@company.com'
  SMTP_PASSWORD: $(SMTP_PASSWORD_SECRET)  # Azure secret variable
  SENDER_EMAIL: 'your-email@company.com'
  RECIPIENTS: 'recipient1@company.com,recipient2@company.com'

3. Replace Placeholders in CI/CD Script

Use sed (Linux) or PowerShell (Windows) to replace placeholders in katalon-config.properties:

sed -i "s/\${SMTP_HOST}/$SMTP_HOST/g" katalon-config.properties
sed -i "s/\${SMTP_PORT}/$SMTP_PORT/g" katalon-config.properties
# Repeat for all variables

4. Execute Katalon with Overridden Config

Run Katalon in Azure with the modified config:

./katalon \
  -noSplash \
  -runMode=console \
  -projectPath="$(pwd)/your-project.prj" \
  -retry=0 \
  -testSuitePath="Test Suites/your-suite" \
  -sendEmail \
  -config="$(pwd)/katalon-config.properties" \
  -executionProfile=azure-cloud \
  -browserType="Remote" \
  -statusDelay=15

5. Alternative: Direct Command-Line Arguments

If you prefer not to use a config file:

./katalon \
  ...other args... \
  -sendEmail \
  -Dnotification.email.enabled=true \
  -Dnotification.email.smtp.host=$SMTP_HOST \
  -Dnotification.email.smtp.port=$SMTP_PORT \
  -Dnotification.email.smtp.username=$SMTP_USER \
  -Dnotification.email.smtp.password=$SMTP_PASSWORD \
  -Dnotification.email.recipients=$RECIPIENTS

6. Handle Security for SMTP (Office 365 Example)

For Office 365 SMTP, ensure these settings are included:

-Dnotification.email.smtp.starttls.enable=true \
-Dnotification.email.smtp.auth=true

7. Attach Reports Programmatically

If Katalon’s native email attachment fails, manually attach the report:

REPORT_PATH="$(pwd)/Reports/*.html"
echo "Attaching report: $REPORT_PATH"
# Use Azure's built-in email task with attachments
- task: CmdLine@2
  inputs:
    script: |
      sendmail -t <<EOF
      To: $RECIPIENTS
      From: $SENDER_EMAIL
      Subject: Azure Test Report
      MIME-Version: 1.0
      Content-Type: multipart/mixed; boundary="KATALON"
      --KATALON
      Content-Type: text/html
      Test execution completed.
      --KATALON
      Content-Type: text/html; name="report.html"
      Content-Disposition: attachment; filename="report.html"
      $(cat $REPORT_PATH)
      --KATALON--
      EOF

8. Full Azure Pipeline YAML Example

jobs:
- job: Run_Katalon_Tests
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: |
        # Install Katalon
        wget https://download.katalon.com/10.1.1/katalon-10.1.1-linux.zip
        unzip katalon-10.1.1-linux.zip -d katalon
        
        # Set permissions
        chmod +x katalon/katalon
        
        # Inject SMTP settings
        sed -i "s/\${SMTP_HOST}/$SMTP_HOST/g" katalon-config.properties
        sed -i "s/\${SMTP_PORT}/$SMTP_PORT/g" katalon-config.properties
        sed -i "s/\${SMTP_USER}/$SMTP_USER/g" katalon-config.properties
        sed -i "s/\${SMTP_PASSWORD}/$SMTP_PASSWORD/g" katalon-config.properties
        sed -i "s/\${SENDER_EMAIL}/$SENDER_EMAIL/g" katalon-config.properties
        sed -i "s/\${RECIPIENTS}/$RECIPIENTS/g" katalon-config.properties
        
        # Run tests with email
        ./katalon/katalon -sendEmail -config=katalon-config.properties ...

This approach ensures email notifications work seamlessly in Azure Cloud without requiring UI interaction.

Thank you, Dinesh. This is what I was looking for.

1 Like

Perfect @senthil.dharmarajan !!