{"record":{"id":"8a166808b8c3b52a","repo":"pentaho/pentaho-kettle","slug":"sendmail-e-tostring-scriptvaluesaddedfunctions","errorCode":null,"errorMessage":"sendMail: {e.toString()}","messagePattern":"sendMail: (.+?)","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1279,"sourceCode":"\n        // Get Recipients\n        String[] strArrRecipients = ( (String) ArgList[2] ).split( \",\" );\n\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();","sourceCodeStart":1261,"sourceCodeEnd":1297,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1261-L1297","documentation":"Thrown by the sendMail JavaScript function when the underlying javax.mail send fails. After building a MimeMessage (SMTP host, from, recipients, subject, body) the function calls Transport.send(msg); any MessagingException or address problem is caught and re-thrown as 'sendMail: ' + e.toString(), so the text after the prefix contains the real Java exception (e.g. UnknownHostException, AuthenticationFailedException).","triggerScenarios":"Calling sendMail(smtpHost, from, recipients, subject, body) where the SMTP host is unresolvable, the server rejects the connection or authentication, a recipient address is malformed, or the mail session cannot be established.","commonSituations":"Wrong SMTP host/port in a Kettle job's JavaScript step; corporate firewall blocking port 25; unauthenticated relaying now required (550 relay denied); typo'd recipient addresses; missing mail.jar/activation dependencies in older setups.","solutions":["Read the text after 'sendMail: ' — it names the underlying Java exception; fix accordingly.","Verify the SMTP hostname and that the port is reachable (telnet host 25) from the Kettle server.","If the server requires auth or TLS, use the Mail step or add mail.smtp.auth/mail.smtp.starttls session properties instead of sendMail().","Validate recipient address syntax before calling; strip whitespace and semicolons not accepted by InternetAddress."],"exampleFix":"// before (host unreachable)\nsendMail(\"smtp.wronghost.local\", from, to, subject, body)\n// after (verify first)\nif ( smtpHost != null && smtpHost.indexOf(\".\") >= 0 ) sendMail(smtpHost, from, to, subject, body)","handlingStrategy":"try-catch","validationCode":"// JS\nfunction safeSendMail(host, from, to, subj, body) {\n  if (!host || !from || !to || subj == null || body == null) return false;\n  try { sendMail(host, from, to, subj, body); return true; } catch (e) { return false; }\n}","typeGuard":"function canSendMail(args) { return args.length === 5 && args.every(function(a){ return a != null; }); }","tryCatchPattern":"try { sendMail(host, from, to, subj, body); } catch (e) { logError(\"sendMail failed: \" + e); }","preventionTips":["Parse the text after 'sendMail: ' — it names the real Java exception","Verify SMTP host/port reachability from the Kettle server","Use the Mail job entry when SMTP auth/TLS is required","Validate recipient address syntax before sending"],"tags":["email","smtp","network","pentaho-kettle"],"backgroundTag":"http-request-failed","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"}