{"record":{"id":"bc4f66cca1488203","repo":"flowable/flowable-engine","slug":"could-not-send-email-incorrect-jndi-configuration","errorCode":null,"errorMessage":"Could not send email: Incorrect JNDI configuration","messagePattern":"Could not send email: Incorrect JNDI configuration","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java","lineNumber":366,"sourceCode":"    }\n\n    protected Session createSession(MailJndiServerConfiguration serverConfiguration) {\n        String sessionJndi = serverConfiguration.getSessionJndi();\n        if (sessionJndi == null) {\n            throw new FlowableIllegalArgumentException(\"sessionJndi has to be set for \" + serverConfiguration);\n        }\n        try {\n            Context ctx;\n            if (sessionJndi.startsWith(\"java:\")) {\n                ctx = new InitialContext();\n            } else {\n                ctx = (Context) new InitialContext().lookup(\"java:comp/env\");\n\n            }\n\n            return (Session) ctx.lookup(sessionJndi);\n        } catch (NamingException e) {\n            throw new FlowableException(\"Could not send email: Incorrect JNDI configuration\", e);\n        }\n    }\n\n    protected Session createSession(MailHostServerConfiguration serverConfiguration) {\n        String host = serverConfiguration.host();\n        if (host == null) {\n            throw new FlowableException(\"Could not send email: no SMTP host is configured\");\n        }\n\n        Properties properties = new Properties(System.getProperties());\n        properties.setProperty(MAIL_TRANSPORT_PROTOCOL, \"smtp\");\n        properties.setProperty(MAIL_PORT, String.valueOf(serverConfiguration.port()));\n        properties.setProperty(MAIL_HOST, host);\n\n        MailHostServerConfiguration.Transport transport = serverConfiguration.transport();\n        properties.setProperty(MAIL_TRANSPORT_STARTTLS_ENABLE, Boolean.toString(serverConfiguration.isStartTlsEnabled()));\n        properties.setProperty(MAIL_TRANSPORT_STARTTLS_REQUIRED, \"false\");\n","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java#L348-L384","documentation":"For a JNDI mail configuration, createSession() performs ctx.lookup(sessionJndi) to fetch the jakarta.mail Session. Any NamingException — the name does not exist, is not bound to a Session, or the InitialContext itself fails — is wrapped as FlowableException \"Could not send email: Incorrect JNDI configuration\".","triggerScenarios":"Sending email with MailJndiServerConfiguration where lookup(sessionJndi) throws NamingException: wrong JNDI name, session resource not deployed, missing 'java:' prefix handling, or missing resource-ref mapping in the web module.","commonSituations":"Typo in the JNDI name (mail/session vs mail/Session); mail resource defined in the app server but no <resource-ref> in web.xml so 'java:comp/env/mail/Session' is unbound; deploying the same WAR on a server without the mail resource; wrong naming context for non-'java:' names.","solutions":["Verify the exact JNDI name as bound by the app server (check server startup logs / admin console)","Declare a <resource-ref> for the mail session in web.xml and map it in the deployment descriptor","Confirm the bound object is a jakarta.mail.Session (not javax.mail.Session — version mismatch)","Test the lookup manually with a small servlet or by listing the JNDI tree"],"exampleFix":"// before\n<property name=\"mailServerJndiName\" value=\"mail/MySession\" />\n// after — fully qualified, matching server binding and resource-ref\n<property name=\"mailServerJndiName\" value=\"java:comp/env/mail/MySession\" />","handlingStrategy":"try-catch","validationCode":"try {\n    new InitialContext().lookup(sessionJndi);\n} catch (NamingException e) {\n    throw new IllegalStateException(\"Mail session not bound at \" + sessionJndi, e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    mailClient.send(mailMessage);\n} catch (FlowableException e) {\n    if (e.getMessage().contains(\"Incorrect JNDI configuration\")) {\n        log.error(\"JNDI lookup failed for mail session; verify binding and resource-ref\", e.getCause());\n    }\n}","preventionTips":["Use the fully qualified JNDI name exactly as bound by the app server","Declare and map <resource-ref> for the mail session in web.xml","Verify the bound object is jakarta.mail.Session, not javax.mail.Session","List the JNDI tree in the target environment before deploying"],"tags":["mail","jndi","naming-exception","configuration"],"backgroundTag":"resource-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}