{"record":{"id":"bee7cf21921981ad","repo":"paascloud/paascloud-master","slug":"opc10040006","errorCode":"OPC10040006","errorMessage":"OPC10040006","messagePattern":"OPC10040006","errorType":"error_code","errorClass":"OpcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptSendMailServiceImpl.java","lineNumber":116,"sourceCode":"\t\t\thelper.setSubject(subject);\n\t\t\thelper.setText(text, true);\n\t\t} catch (MessagingException e) {\n\t\t\tlog.error(\"生成邮件消息体, 出现异常={}\", e.getMessage(), e);\n\t\t\tthrow new OpcBizException(ErrorCodeEnum.OPC10040005);\n\t\t}\n\t\treturn mimeMessage;\n\t}\n\n\t@Override\n\tpublic int sendTemplateMail(Map<String, Object> model, String templateLocation, String subject, Set<String> to) {\n\t\tlog.info(\"sendTemplateMail - 发送模板邮件. subject={}, model={}, to={}, templateLocation={}\", subject, model, to, templateLocation);\n\n\t\tString text;\n\t\ttry {\n\t\t\ttext = optVelocityService.getTemplate(model, templateLocation);\n\t\t} catch (IOException | TemplateException e) {\n\t\t\tlog.info(\"sendTemplateMail [FAIL] ex={}\", e.getMessage(), e);\n\t\t\tthrow new OpcBizException(ErrorCodeEnum.OPC10040006, e);\n\t\t}\n\t\treturn this.sendTemplateMail(subject, text, to);\n\t}\n\n\n\tprivate String[] setToArray(Set<String> to) {\n\t\tPreconditions.checkArgument(PublicUtil.isNotEmpty(to), \"请输入收件人邮箱\");\n\n\t\tSet<String> toSet = Sets.newHashSet();\n\t\tfor (String toStr : to) {\n\t\t\ttoStr = toStr.trim();\n\t\t\tif (PubUtils.isEmail(toStr)) {\n\t\t\t\ttoSet.add(toStr);\n\t\t\t}\n\t\t}\n\t\tif (PublicUtil.isEmpty(toSet)) {\n\t\t\treturn null;\n\t\t}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptSendMailServiceImpl.java#L98-L134","documentation":"OPC10040006 (\"获取模板信息失败\") is thrown by OptSendMailServiceImpl.sendTemplateMail when the Velocity template rendering (optVelocityService.getTemplate) fails with IOException or TemplateException. IOException usually means the template resource cannot be found/read; TemplateException means the template parsed/rendered badly (bad syntax, missing variable directives). The exception wraps the cause and the mail is never sent.","triggerScenarios":"Calling sendTemplateMail(model, templateLocation, subject, to) where templateLocation does not resolve to an existing template resource, or the .vm template has Velocity syntax errors, or the model lacks variables the template requires.","commonSituations":"Renaming/moving template files without updating templateLocation; packaging templates outside the jar so classpath loading fails; Velocity directive typos after editing; template referencing a model key removed in a new release.","solutions":["Verify templateLocation resolves on the classpath (e.g. starts with a correct classpath prefix and the file exists in the built artifact).","Check the wrapped IOException/TemplateException in the log — TemplateException gives line/column of the syntax error.","Fix Velocity template syntax errors (#if/#foreach directives, $variable references) reported in the cause.","Ensure the model map contains every variable the template references.","Add a startup check/test that renders each registered template to catch missing templates at deploy time."],"exampleFix":"// before: template path typo fails at runtime\nmailService.sendTemplateMail(model, \"/templates/mail/notif.vm\", subject, to);\n// after: fail fast if template missing\nclassPathResource \"/templates/mail/notify.vm\";\ntry (InputStream in = getClass().getResourceAsStream(templateLocation)) {\n    if (in == null) { throw new IllegalStateException(\"template missing: \" + templateLocation); }\n}\nmailService.sendTemplateMail(model, \"/templates/mail/notify.vm\", subject, to);","handlingStrategy":"validation","validationCode":"try (InputStream in = getClass().getResourceAsStream(templateLocation)) {\n    if (in == null) {\n        throw new IllegalStateException(\"Mail template not on classpath: \" + templateLocation);\n    }\n}","typeGuard":"boolean templateExists(String location) {\n    return getClass().getResource(location) != null;\n}","tryCatchPattern":"try {\n    mailService.sendTemplateMail(model, templateLocation, subject, to);\n} catch (OpcBizException e) {\n    if (e.getCode() == 10040006) {\n        log.error(\"Mail template render failed for {}\", templateLocation, e.getCause());\n    }\n    throw e;\n}","preventionTips":["Keep templates inside src/main/resources and verify they land in the jar.","Add a unit test that renders every template with a full model.","Fix Velocity syntax errors immediately when editing templates.","Version-control template changes together with model changes.","Use constants for template locations instead of inline strings."],"tags":["velocity","template","email"],"backgroundTag":"file-not-found","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}