pentaho/pentaho-kettle · error · JavaScriptException

The function call sendMail requires 5 arguments.

Error message

The function call sendMail requires 5 arguments.

What it means

Thrown by sendMail when the function is invoked with an argument count other than 5. The function requires exactly smtpHost, from, recipients, subject, and body; an else branch on the arity check raises this runtime error before any mail session is created.

Solutions

  1. Supply all five arguments in order: smtpHost, from, recipients, subject, body.
  2. Remove any 6th+ arguments — authentication is not part of this signature; use the Mail job entry for SMTP auth.
  3. Check for undefined variables at the call site that silently change arity in generated code.
  4. Move to Pentaho's 'Send Mail' job entry or Mail step for richer options.

Example fix

// before
sendMail(smtpHost, from, to, subject)
// after
sendMail(smtpHost, from, to, subject, bodyText)
Defensive patterns

Strategy: validation

Validate before calling

// JS
if (arguments && arguments.length !== 5) { throw new Error("sendMail needs smtpHost, from, recipients, subject, body"); }
sendMail(smtpHost, from, recipients, subject, body);

Type guard

function sendMailArgsOk(a) { return Array.isArray(a) && a.length === 5 && a.every(function(x){ return x != null; }); }

Try / catch

try { sendMail(h, f, t, s, b); } catch (e) { if (String(e).indexOf("requires 5 arguments") >= 0) logError("wrong arity"); else throw e; }

Prevention

When it happens

Trigger: Calling sendMail() with fewer than 5 arguments (e.g. omitting subject/body) or more than 5 (e.g. adding an auth parameter that the function does not support).

Common situations: Developers assuming sendMail supports credentials as a 6th argument; forgetting the body when sending short notifications; scripts refactored so a variable is undefined and dropped from the call site.

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/5cf654cb5dcc3d4c. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1282

        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 Context.reportRuntimeError( "sendMail: " + e.toString() );
      }
    } else {
      throw Context.reportRuntimeError( "The function call sendMail requires 5 arguments." );
    }
  }

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

View on GitHub (pinned to f3058517a1)