{"record":{"id":"0ac2a9ecc13dd73c","repo":"pentaho/pentaho-kettle","slug":"the-function-call-sendmail-requires-5-arguments","errorCode":null,"errorMessage":"The function call sendMail requires 5 arguments.","messagePattern":"The function call sendMail requires 5 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1248,"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 new RuntimeException( \"sendMail: \" + e.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call sendMail requires 5 arguments.\" );\n    }\n  }\n\n  public static String upper( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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) undefinedValue;\n        }\n        sRC = (String) ArgList[0];\n        sRC = sRC.toUpperCase();\n      } catch ( Exception e ) {\n        throw new RuntimeException( \"The function call upper is not valid : \" + e.getMessage() );\n      }","sourceCodeStart":1230,"sourceCodeEnd":1266,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1230-L1266","documentation":"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.","triggerScenarios":"sendMail(...) called with fewer or more than 5 arguments, e.g. omitting the subject or passing cc/bcc as a 6th argument (not supported).","commonSituations":"Trying the common JavaScript mail signatures with cc/bcc parameters; forgetting one of the five required arguments when refactoring a script.","solutions":["Provide exactly 5 arguments: server, from, recipients, subject, body.","For cc/bcc or attachments, use the dedicated Mail transform/Job entry instead of the script function.","Combine multiple recipients into the single recipient argument (comma/semicolon-separated, as supported by the implementation)."],"exampleFix":"// before\nsendMail('smtp.corp.com', 'etl@corp.com', 'ops@corp.com', 'done')\n// after\nsendMail('smtp.corp.com', 'etl@corp.com', 'ops@corp.com', 'Job done', 'OK')","handlingStrategy":"validation","validationCode":"function safeSendMail(host, from, to, subject, body) {\n  var parts = [host, from, to, subject, body];\n  if (arguments.length !== 5 || parts.some(function(p){ return p === undefined; })) {\n    throw new Error('sendMail needs exactly 5 defined arguments');\n  }\n  sendMail(host, from, to, subject, body);\n}","typeGuard":null,"tryCatchPattern":"try { sendMail(h, f, t, s, b); }\ncatch (e) { if (/requires 5 arguments/.test(e.message)) Logger.logError('bad sendMail call'); throw e; }","preventionTips":["Keep the 5-argument order memorized: server, from, to, subject, body.","Use a wrapper function to centralize argument checking.","Move cc/bcc/attachment use cases to the Mail step."],"tags":["email","argument-count","scripting-step"],"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"}