Skip to content

[fix] Make email notifier optional when spring.mail is not configured - #4345

Open
jvanderen1 wants to merge 2 commits into
apache:masterfrom
jvanderen1:cursor/optional-email-notifier-546e
Open

[fix] Make email notifier optional when spring.mail is not configured#4345
jvanderen1 wants to merge 2 commits into
apache:masterfrom
jvanderen1:cursor/optional-email-notifier-546e

Conversation

@jvanderen1

@jvanderen1 jvanderen1 commented Aug 24, 2026

Copy link
Copy Markdown

What's changed?

Fixes #4344

HertzBeat fails to start when spring.mail is omitted because EmailAlertNotifyHandlerImpl constructor-injects JavaMailSender, which Spring Boot only auto-configures when mail host properties are set. Docs and sample configs already describe mail as optional (“Not required if you don’t use email notify”), but missing mail config becomes a fatal startup failure / Docker restart crash loop.

This change:

  • Injects ObjectProvider<JavaMailSender> and falls back to a local JavaMailSenderImpl when no mail bean exists, so startup succeeds without spring.mail
  • Still supports email via spring.mail or UI/DB mail server settings
  • Returns a clear AlertNoticeException when email notify is used without any mail configuration
  • Aligns application.yml comments and deploy/email docs with the optional-mail behavior
  • Adds unit coverage for startup without a mail bean and the not-configured send path

DietPi smoke test (SHA 03956af9a87e9a2c214e9808e28f253edaf6bd8a)

Tested by overlaying this fix onto apache/hertzbeat:1.8.0 (local smoke image built from the SHA above).

Check Result
Config spring.mail fully omitted
Startup Container healthy, Restarts=0 for several minutes
Missing-bean crash None — no JavaMailSender required-bean startup failure
Startup log spring.mail is not configured; email notify will require UI/DB mail server settings
Email negative /api/notice/receiver/send-test-msg[Email Notify Error] Mail server is not configured. Set spring.mail in application.yml or enable email settings in the UI.
Webhook / Discord HertzBeat reached Discord janitor; stock send-test-msg got Discord 50006 (empty message — test payload/template limitation), not a crash; direct janitor embed POST returned 200
Unit tests EmailAlertNotifyHandlerImplTest 5/5 passed

Note: Discord send-test-msg was not claimed as a fully rendered Discord message; empty-body 50006 is a template/payload limitation of the stock test path, not a regression from this fix.

Checklist

  • I have read the Contributing Guide
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Add or update API

  • I have added the necessary e2e tests and all cases have passed.

cursoragent and others added 2 commits August 24, 2026 00:50
EmailAlertNotifyHandlerImpl no longer requires a JavaMailSender bean at
startup. Without spring.mail, HertzBeat starts normally and email notify
reports a clear error until mail is configured via yml or the UI.

Co-authored-by: Joshua Van Deren <jvanderen1@users.noreply.github.com>
Avoid UnnecessaryStubbingException when covering startup without a
JavaMailSender bean and the mail-not-configured send path.

Co-authored-by: Joshua Van Deren <jvanderen1@users.noreply.github.com>
@github-actions github-actions Bot added doc Improvements or additions to documentation backend docker-compose docker script labels Aug 24, 2026
@jvanderen1 jvanderen1 changed the title Cursor/optional email notifier 546e [fix] Make email notifier optional when spring.mail is not configured Aug 24, 2026
@jvanderen1
jvanderen1 marked this pull request as ready for review August 24, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend doc Improvements or additions to documentation docker docker-compose script

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HertzBeat fails to start when spring.mail is omitted (docs say optional)

2 participants