pentaho/pentaho-kettle · error · RuntimeException

The function call sendMail requires 5 arguments.

Error message

The function call sendMail requires 5 arguments.

What it means

Arity guard in ScriptAddedFunctions.sendMail: the script invocation did not pass exactly 5 arguments (SMTP host or session context, sender, recipients, subject, body). The function builds and sends the MIME message from ArgList[0..4], so other counts are rejected before any mail API is used.

Solutions

  1. Provide exactly 5 arguments: server, from, recipients, subject, body.
  2. For cc/bcc or attachments, use the dedicated Mail transform/Job entry instead of the script function.
  3. Combine multiple recipients into the single recipient argument (comma/semicolon-separated, as supported by the implementation).

Example fix

// before
sendMail('smtp.corp.com', 'etl@corp.com', 'ops@corp.com', 'done')
// after
sendMail('smtp.corp.com', 'etl@corp.com', 'ops@corp.com', 'Job done', 'OK')
Defensive patterns

Strategy: validation

Validate before calling

function safeSendMail(host, from, to, subject, body) {
  var parts = [host, from, to, subject, body];
  if (arguments.length !== 5 || parts.some(function(p){ return p === undefined; })) {
    throw new Error('sendMail needs exactly 5 defined arguments');
  }
  sendMail(host, from, to, subject, body);
}

Try / catch

try { sendMail(h, f, t, s, b); }
catch (e) { if (/requires 5 arguments/.test(e.message)) Logger.logError('bad sendMail call'); throw e; }

Prevention

When it happens

Trigger: sendMail(...) called with fewer or more than 5 arguments, e.g. omitting the subject or passing cc/bcc as a 6th argument (not supported).

Common situations: Trying the common JavaScript mail signatures with cc/bcc parameters; forgetting one of the five required arguments when refactoring a script.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/0ac2a9ecc13dd73c. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1248

        InternetAddress[] addressTo = new InternetAddress[strArrRecipients.length];
        for ( int i = 0; i < strArrRecipients.length; i++ ) {
          addressTo[i] = new InternetAddress( strArrRecipients[i] );
        }
        msg.setRecipients( Message.RecipientType.TO, addressTo );

        // Optional : You can also set your custom headers in the Email if you Want
        msg.addHeader( "MyHeaderName", "myHeaderValue" );

        // Setting the Subject and Content Type
        msg.setSubject( (String) ArgList[3] );
        msg.setContent( ArgList[4], "text/plain" );
        Transport.send( msg );
      } catch ( Exception e ) {
        throw new RuntimeException( "sendMail: " + e.toString() );
      }
    } else {
      throw new RuntimeException( "The function call sendMail requires 5 arguments." );
    }
  }

  public static String upper( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    String sRC = "";
    if ( ArgList.length == 1 ) {
      try {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return (String) undefinedValue;
        }
        sRC = (String) ArgList[0];
        sRC = sRC.toUpperCase();
      } catch ( Exception e ) {
        throw new RuntimeException( "The function call upper is not valid : " + e.getMessage() );
      }

View on GitHub (pinned to f3058517a1)