{"record":{"id":"f1f8fb4ec7eac914","repo":"pentaho/pentaho-kettle","slug":"mailconnection-error-savingmessagecontent","errorCode":null,"errorMessage":"MailConnection.Error.SavingMessageContent","messagePattern":"MailConnection\\.Error\\.SavingMessageContent","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java","lineNumber":893,"sourceCode":"  /**\n   * Export message content to a filename.\n   *\n   * @param filename\n   *          the target filename\n   * @param foldername\n   *          the parent folder of filename\n   * @throws KettleException\n   */\n\n  public void saveMessageContentToFile( String filename, String foldername ) throws KettleException {\n    OutputStream os = null;\n    try {\n      os = KettleVFS.getInstance( bowl )\n        .getOutputStream( foldername + ( foldername.endsWith( \"/\" ) ? \"\" : \"/\" ) + filename, false );\n      getMessage().writeTo( os );\n      updateSavedMessagesCounter();\n    } catch ( Exception e ) {\n      throw new KettleException( BaseMessages.getString( PKG, \"MailConnection.Error.SavingMessageContent\", \"\"\n        + this.message.getMessageNumber(), filename, foldername ), e );\n    } finally {\n      if ( os != null ) {\n        IOUtils.closeQuietly( os );\n      }\n    }\n  }\n\n  /**\n   * Save attached files to a folder.\n   *\n   * @param foldername\n   *          the target foldername\n   * @throws KettleException\n   */\n  public void saveAttachedFiles( String foldername ) throws KettleException {\n    saveAttachedFiles( foldername, null );\n  }","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java#L875-L911","documentation":"saveMessageContentToFile() wraps exceptions from opening the output stream via KettleVFS and writing message.writeTo(os) into a KettleException with MailConnection.Error.SavingMessageContent, including message number, filename and target folder. It means an email could not be exported to disk.","triggerScenarios":"saveMessageContentToFile(filename, foldername) when the VFS output stream can't be created (missing directory, permissions) or getMessage().writeTo(os) fails (message content unreadable, disk full, stream closed).","commonSituations":"Target directory doesn't exist or is read-only, disk quota/full, illegal characters in filename on the OS, very large attachments exceeding disk space, message content corrupted on server.","solutions":["Create the target directory beforehand and verify write permissions for the Pentaho user.","Check free disk space and quota on the export volume.","Sanitize the generated filename (strip illegal characters like : ? * | on Windows).","Inspect the chained cause to distinguish VFS open failure vs message writeTo failure."],"exampleFix":"// before\nFile dir = new File(\"/exports/mail\");\nmailConnection.saveMessageContentToFile(\"msg.eml\", \"/exports/mail\");\n// after\ndir.mkdirs();\nmailConnection.saveMessageContentToFile(\"msg.eml\", \"/exports/mail\");","handlingStrategy":"validation","validationCode":"java.io.File dir = new java.io.File(targetFolder);\nif (!dir.isDirectory()) dir.mkdirs();\nif (!dir.canWrite()) throw new KettleException(\"No write permission: \" + targetFolder);\nString safeName = filename.replaceAll(\"[/\\\\\\\\:*?\\\"<>|]\", \"_\");","typeGuard":null,"tryCatchPattern":"try {\n  mailConnection.saveMessageContentToFile(filename, targetFolder);\n} catch (KettleException e) {\n  logError(\"Could not save message \" + msgNr + \" to \" + targetFolder + \": \" + e.getCause().getMessage(), e);\n  throw e;\n}","preventionTips":["Pre-create export directories with correct ownership","Monitor disk free space on export volumes","Sanitize filenames for the target OS","Include message number in filenames to avoid collisions"],"tags":["io","file-write","javamail","kettle","email"],"backgroundTag":"file-write-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"}