[fix] Make email notifier optional when spring.mail is not configured - #4345
Open
jvanderen1 wants to merge 2 commits into
Open
[fix] Make email notifier optional when spring.mail is not configured#4345jvanderen1 wants to merge 2 commits into
jvanderen1 wants to merge 2 commits into
Conversation
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>
4 tasks
jvanderen1
marked this pull request as ready for review
August 24, 2026 01:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
Fixes #4344
HertzBeat fails to start when
spring.mailis omitted becauseEmailAlertNotifyHandlerImplconstructor-injectsJavaMailSender, 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:
ObjectProvider<JavaMailSender>and falls back to a localJavaMailSenderImplwhen no mail bean exists, so startup succeeds withoutspring.mailspring.mailor UI/DB mail server settingsAlertNoticeExceptionwhen email notify is used without any mail configurationapplication.ymlcomments and deploy/email docs with the optional-mail behaviorDietPi smoke test (SHA
03956af9a87e9a2c214e9808e28f253edaf6bd8a)Tested by overlaying this fix onto
apache/hertzbeat:1.8.0(local smoke image built from the SHA above).spring.mailfully omittedJavaMailSenderrequired-bean startup failurespring.mail is not configured; email notify will require UI/DB mail server settings/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.send-test-msggot Discord50006(empty message — test payload/template limitation), not a crash; direct janitor embed POST returned 200EmailAlertNotifyHandlerImplTest5/5 passedNote: Discord
send-test-msgwas not claimed as a fully rendered Discord message; empty-body50006is a template/payload limitation of the stock test path, not a regression from this fix.Checklist
Add or update API