{"record":{"id":"5cf654cb5dcc3d4c","repo":"pentaho/pentaho-kettle","slug":"the-function-call-sendmail-requires-5-arguments-5cf654","errorCode":null,"errorMessage":"The function call sendMail requires 5 arguments.","messagePattern":"The function call sendMail requires 5 arguments\\.","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1282,"sourceCode":"\n        InternetAddress[] addressTo = new InternetAddress[strArrRecipients.length];\n        for ( int i = 0; i < strArrRecipients.length; i++ ) {\n          addressTo[i] = new InternetAddress( strArrRecipients[i] );\n        }\n        msg.setRecipients( Message.RecipientType.TO, addressTo );\n\n        // Optional : You can also set your custom headers in the Email if you Want\n        msg.addHeader( \"MyHeaderName\", \"myHeaderValue\" );\n\n        // Setting the Subject and Content Type\n        msg.setSubject( (String) ArgList[3] );\n        msg.setContent( ArgList[4], \"text/plain\" );\n        Transport.send( msg );\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( \"sendMail: \" + e.toString() );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call sendMail requires 5 arguments.\" );\n    }\n  }\n\n  public static String upper( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    String sRC = \"\";\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) Context.getUndefinedValue();\n        }\n        sRC = Context.toString( ArgList[0] );\n        sRC = sRC.toUpperCase();\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( \"The function call upper is not valid : \" + e.getMessage() );\n      }","sourceCodeStart":1264,"sourceCodeEnd":1300,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1264-L1300","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Supply all five arguments in order: smtpHost, from, recipients, subject, body.","Remove any 6th+ arguments — authentication is not part of this signature; use the Mail job entry for SMTP auth.","Check for undefined variables at the call site that silently change arity in generated code.","Move to Pentaho's 'Send Mail' job entry or Mail step for richer options."],"exampleFix":"// before\nsendMail(smtpHost, from, to, subject)\n// after\nsendMail(smtpHost, from, to, subject, bodyText)","handlingStrategy":"validation","validationCode":"// JS\nif (arguments && arguments.length !== 5) { throw new Error(\"sendMail needs smtpHost, from, recipients, subject, body\"); }\nsendMail(smtpHost, from, recipients, subject, body);","typeGuard":"function sendMailArgsOk(a) { return Array.isArray(a) && a.length === 5 && a.every(function(x){ return x != null; }); }","tryCatchPattern":"try { sendMail(h, f, t, s, b); } catch (e) { if (String(e).indexOf(\"requires 5 arguments\") >= 0) logError(\"wrong arity\"); else throw e; }","preventionTips":["Always supply all 5 arguments in order","Do not add a 6th credentials argument — it is unsupported","Check that variables at the call site are defined","Prefer the Send Mail job entry for advanced options"],"tags":["javascript","argument-count","email","pentaho-kettle"],"backgroundTag":"missing-required-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}