{"record":{"id":"47ab6766f787cd96","repo":"apache/shenyu","slug":"email-notify-error-e-getmessage","errorCode":null,"errorMessage":"[Email Notify Error] \" + e.getMessage()","messagePattern":"\\[Email Notify Error\\] \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"AlertNoticeException","httpStatus":null,"severity":"error","filePath":"shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java","lineNumber":71,"sourceCode":"    \n    @Override\n    public void send(final AlertReceiverDTO receiver, final AlarmContent alert) throws AlertNoticeException {\n        try {\n            MimeMessage mimeMessage = javaMailSender.createMimeMessage();\n            MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, \"UTF-8\");\n            messageHelper.setSubject(\"ShenYu Alarm\");\n            //Set sender Email 设置发件人Email\n            messageHelper.setFrom(emailFromUser);\n            //Set recipient Email 设定收件人Email\n            messageHelper.setTo(receiver.getEmail());\n            messageHelper.setSentDate(new Date());\n            //Build email templates 构建邮件模版\n            String process = buildAlertHtmlTemplate(alert);\n            //Set Email Content Template 设置邮件内容模版\n            messageHelper.setText(process, true);\n            javaMailSender.send(mimeMessage);\n        } catch (Exception e) {\n            throw new AlertNoticeException(\"[Email Notify Error] \" + e.getMessage());\n        }\n    }\n    \n    private String buildAlertHtmlTemplate(final AlarmContent alert) {\n        // Introduce thymeleaf context parameters to render pages\n        Context context = new Context();\n        context.setVariable(\"nameTitle\", \"ShenYu Alarm\");\n        context.setVariable(\"nameTriggerTime\", \"Alarm Time\");\n        context.setVariable(\"nameContent\", \"Alarm Content\");\n        context.setVariable(\"content\", alert.getContent());\n        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");\n        Date alertTime = alert.getDateCreated();\n        if (Objects.isNull(alertTime)) {\n            alertTime = new Date();\n        }\n        String alarmTime = simpleDateFormat.format(alertTime);\n        context.setVariable(\"lastTriggerTime\", alarmTime);\n        return templateEngine.process(\"mailAlarm\", context);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java#L53-L89","documentation":"EmailAlertNotifyStrategy.send wraps any exception in the mail-sending pipeline (template rendering, MIME message setup, javaMailSender.send) into AlertNoticeException(\"[Email Notify Error] \" + e.getMessage()). The alert email was not delivered; the cause is logged and only the message is carried forward.","triggerScenarios":"Calling send() when building the Thymeleaf template or sending via JavaMailSender throws: SMTP connect failure, authentication failure, bad host/port, TLS errors.","commonSituations":"Wrong SMTP host/port/SSL settings in mail config; wrong username/password or expired mail credentials; mail server unreachable from the container; firewall blocking port 25/465/587.","solutions":["Verify spring.mail (host, port, username, password, smtp auth/ssl) configuration","Test SMTP connectivity from the app host (telnet host port) and open firewall ports if blocked","Confirm mail credentials are valid and the account allows SMTP/auth (some providers need an app password)","Check logs for the original exception stack to distinguish template-render errors from transport errors"],"exampleFix":"// before\ncatch (Exception e) {\n    throw new AlertNoticeException(\"[Email Notify Error] \" + e.getMessage());\n}\n// after\ncatch (Exception e) {\n    throw new AlertNoticeException(\"[Email Notify Error] \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"// verify mail config before sending\nObjects.requireNonNull(javaMailSender, \"mail sender not configured\");\n// and confirm host/port/credentials set in spring.mail properties","typeGuard":null,"tryCatchPattern":"try {\n    emailStrategy.send(config, alert);\n} catch (AlertNoticeException e) {\n    log.error(\"Email alert failed: {}\", e.getMessage(), e);\n    // fall back to another alert channel\n}","preventionTips":["Smoke-test SMTP credentials and connectivity at startup","Use app-specific passwords where providers require them","Keep mail config in the active Spring profile validated in CI"],"tags":["email","smtp","alert","configuration"],"backgroundTag":"network-request-failed","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}