apache/shenyu · error · AlertNoticeException

[Email Notify Error] " + e.getMessage()

Error message

[Email Notify Error] " + e.getMessage()

What it means

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.

Solutions

  1. Verify spring.mail (host, port, username, password, smtp auth/ssl) configuration
  2. Test SMTP connectivity from the app host (telnet host port) and open firewall ports if blocked
  3. Confirm mail credentials are valid and the account allows SMTP/auth (some providers need an app password)
  4. Check logs for the original exception stack to distinguish template-render errors from transport errors

Example fix

// before
catch (Exception e) {
    throw new AlertNoticeException("[Email Notify Error] " + e.getMessage());
}
// after
catch (Exception e) {
    throw new AlertNoticeException("[Email Notify Error] " + e.getMessage(), e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// verify mail config before sending
Objects.requireNonNull(javaMailSender, "mail sender not configured");
// and confirm host/port/credentials set in spring.mail properties

Try / catch

try {
    emailStrategy.send(config, alert);
} catch (AlertNoticeException e) {
    log.error("Email alert failed: {}", e.getMessage(), e);
    // fall back to another alert channel
}

Prevention

When it happens

Trigger: Calling send() when building the Thymeleaf template or sending via JavaMailSender throws: SMTP connect failure, authentication failure, bad host/port, TLS errors.

Common situations: 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.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/47ab6766f787cd96. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java:71

    
    @Override
    public void send(final AlertReceiverDTO receiver, final AlarmContent alert) throws AlertNoticeException {
        try {
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
            messageHelper.setSubject("ShenYu Alarm");
            //Set sender Email 设置发件人Email
            messageHelper.setFrom(emailFromUser);
            //Set recipient Email 设定收件人Email
            messageHelper.setTo(receiver.getEmail());
            messageHelper.setSentDate(new Date());
            //Build email templates 构建邮件模版
            String process = buildAlertHtmlTemplate(alert);
            //Set Email Content Template 设置邮件内容模版
            messageHelper.setText(process, true);
            javaMailSender.send(mimeMessage);
        } catch (Exception e) {
            throw new AlertNoticeException("[Email Notify Error] " + e.getMessage());
        }
    }
    
    private String buildAlertHtmlTemplate(final AlarmContent alert) {
        // Introduce thymeleaf context parameters to render pages
        Context context = new Context();
        context.setVariable("nameTitle", "ShenYu Alarm");
        context.setVariable("nameTriggerTime", "Alarm Time");
        context.setVariable("nameContent", "Alarm Content");
        context.setVariable("content", alert.getContent());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date alertTime = alert.getDateCreated();
        if (Objects.isNull(alertTime)) {
            alertTime = new Date();
        }
        String alarmTime = simpleDateFormat.format(alertTime);
        context.setVariable("lastTriggerTime", alarmTime);
        return templateEngine.process("mailAlarm", context);

View on GitHub (pinned to 567142e072)