{"record":{"id":"845887c450586f65","repo":"pentaho/pentaho-kettle","slug":"sendmail-e-tostring","errorCode":null,"errorMessage":"sendMail: \" + e.toString()","messagePattern":"sendMail: \" \\+ e\\.toString\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1245,"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 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();","sourceCodeStart":1227,"sourceCodeEnd":1263,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1227-L1263","documentation":"Thrown by the sendMail() helper of the PDI Script step when Transport.send() or any mail-session setup fails. The original exception's toString() (e.g. javax.mail.MessagingException, UnknownHostException, AuthenticationFailedException) is appended, so the root cause is visible in the message.","triggerScenarios":"Calling sendMail(smtpServer, from, recipient, subject, body) where the SMTP host is unreachable/wrong, the port is blocked, authentication fails, or mail.jar/activation.jar connectivity issues occur.","commonSituations":"Firewall blocks outbound port 25, SMTP server hostname typo, no mail relay permission from the Pentaho server, TLS/SSL required by the server but not used, DNS failure inside containerized deployments.","solutions":["Read the appended cause: fix the SMTP host/port per the wrapped exception (UnknownHostException -> hostname; Connection refused -> port/firewall; AuthenticationFailedException -> credentials).","Verify network reachability from the Pentaho server: telnet/smtp connectivity to the mail host and port.","Check that the SMTP server allows relay from this host, or add valid authentication if required.","Prefer the dedicated Mail step or configure a central mail host in Kettle properties (KETTLE_SYSTEM_HOSTS / mail settings) instead of ad-hoc script sendMail."],"exampleFix":"// before\nsendMail('smtp.corp.local', 'etl@corp.com', 'ops@corp.com', 'Job done', 'OK')\n// after (use a reachable, verified host)\nsendMail('smtp.corp.com', 'etl@corp.com', 'ops@corp.com', 'Job done', 'OK')","handlingStrategy":"try-catch","validationCode":"function canReachHost(host) {\n  var s = new java.net.Socket();\n  try { s.connect(new java.net.InetSocketAddress(host, 25), 3000); s.close(); return true; }\n  catch (e) { return false; }\n}\n// call only if canReachMailHost before sendMail(...)","typeGuard":null,"tryCatchPattern":"try { sendMail(host, from, to, subj, body); }\ncatch (e) {\n  var cause = e.message.replace('sendMail: ', '');\n  Logger.logError('SMTP failure: ' + cause);\n  if (/UnknownHost/.test(cause)) { /* fix hostname */ }\n  throw e;\n}","preventionTips":["Verify SMTP host/port reachability from the Pentaho server before go-live.","Open firewall rules for the mail port in containerized/DMZ deployments.","Confirm relay permissions or credentials on the mail server.","Prefer the dedicated Mail job entry for production mail."],"tags":["email","smtp","network","scripting-step"],"backgroundTag":"smtp-send-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"}