{"record":{"id":"be8773eca0c099f2","repo":"elunez/eladmin","slug":"error-be8773","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java","lineNumber":82,"sourceCode":"    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void send(EmailVo emailVo, EmailConfig emailConfig){\n        if(emailConfig.getId() == null){\n            throw new BadRequestException(\"请先配置，再操作\");\n        }\n        // 封装\n        MailAccount account = new MailAccount();\n        // 设置用户\n        String user = emailConfig.getFromUser().split(\"@\")[0];\n        account.setUser(user);\n        account.setHost(emailConfig.getHost());\n        account.setPort(Integer.parseInt(emailConfig.getPort()));\n        account.setAuth(true);\n        try {\n            // 对称解密\n            account.setPass(EncryptUtils.desDecrypt(emailConfig.getPass()));\n        } catch (Exception e) {\n            throw new BadRequestException(e.getMessage());\n        }\n        account.setFrom(emailConfig.getUser()+\"<\"+emailConfig.getFromUser()+\">\");\n        // ssl方式发送\n        account.setSslEnable(true);\n        // 使用STARTTLS安全连接\n        account.setStarttlsEnable(true);\n        // 解决jdk8之后默认禁用部分tls协议，导致邮件发送失败的问题\n        account.setSslProtocols(\"TLSv1 TLSv1.1 TLSv1.2\");\n        String content = emailVo.getContent();\n        // 发送\n        try {\n            int size = emailVo.getTos().size();\n            Mail.create(account)\n                    .setTos(emailVo.getTos().toArray(new String[size]))\n                    .setTitle(emailVo.getSubject())\n                    .setContent(content)\n                    .setHtml(true)\n                    //关闭session","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java#L64-L100","documentation":"This is BadRequestException(e.getMessage()) rethrown from the catch block around EncryptUtils.desDecrypt(emailConfig.getPass()) while assembling the hutool MailAccount in EmailServiceImpl.send. The '{}' message means it is a pass-through of the underlying decryption exception's text — typically hutool's CryptoException ('decrypt error...' or 'InvalidKeyException: Invalid key length') when the stored password cannot be DES-decrypted with the fixed key.","triggerScenarios":"Any email send (verification code, admin send-email tool) after config was saved, where email_config.pass was stored in a format that isn't DES-encrypted with EncryptUtils' expected key — e.g. plaintext password saved by an older version or entered manually into the DB, or data migrated/ truncated.","commonSituations":"Upgrading eladmin versions where the pass encoding changed; someone editing email_config.pass directly in the database to plaintext; multi-byte/special characters in the password breaking DES block alignment; config row written by an external tool bypassing the encrypt step.","solutions":["Re-save the email config through the admin UI so the password is DES-encrypted by the normal save path (it encrypts with EncryptUtils before persisting).","Check email_config.pass value in DB: it must be the encrypted ciphertext, not the plaintext SMTP password.","Verify the full ciphertext survived any DB migration (no truncation — column length).","Look at the wrapped exception in logs to confirm whether it is key-length/block-size related versus charset corruption."],"exampleFix":"// before\ntry {\n    account.setPass(EncryptUtils.desDecrypt(emailConfig.getPass()));\n} catch (Exception e) {\n    throw new BadRequestException(e.getMessage());\n}\n\n// after: clearer diagnostics while keeping config value untouched\ntry {\n    account.setPass(EncryptUtils.desDecrypt(emailConfig.getPass()));\n} catch (Exception e) {\n    log.error(\"DES decrypt of email password failed; re-save email config\", e);\n    throw new BadRequestException(\"邮箱密码解密失败，请重新保存邮箱配置\");\n}","handlingStrategy":"try-catch","validationCode":"// detect an unusable stored password before send\nEmailConfig config = emailService.find();\nboolean passLooksEncrypted;\ntry { EncryptUtils.desDecrypt(config.getPass()); passLooksEncrypted = true; }\ncatch (Exception e) { passLooksEncrypted = false; }\nif (!passLooksEncrypted) { throw new BadRequestException(\"邮箱密码无效，请重新保存邮箱配置\"); }","typeGuard":null,"tryCatchPattern":"try { emailService.send(emailVo, config); } catch (BadRequestException e) { // passthrough message: log it, and if it mentions decrypt/key, force re-saving email config rather than retrying } }","preventionTips":["Only write email_config.pass via the admin save flow (it DES-encrypts); never via SQL.","After upgrades or migrations, re-save email config once to re-encrypt the password.","Log the passthrough message server-side; the client message alone is often ambiguous."],"tags":["email","encryption","des","configuration","pass-through-exception"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}