zenml
zenml copied to clipboard
SMTP Email Alerter integration + make generic Alerter steps
The PR adds a new SMTP Email Alerter integration to ZenML, enabling users to send email notifications on pipeline steps events. It also implements a unified alerter approach with a standardized AlerterMessage model across all alerter types.
Key Features
-
New SMTP Email Alerter Integration
- Support for HTML and plain text emails
- Professional HTML email formatting
- Proper traceback formatting in emails
- Markdown-to-HTML conversion for better email display
- Support for common email providers like Gmail, Outlook, etc.
-
Unified Alerter Architecture
- Standardized
AlerterMessagemodel for consistent alerter interfaces - Generic
alerter_post_stepandalerter_ask_stepfor all alerter types - Improved type handling across alerter components
- Proper deprecation warnings for specialized alerter steps
- Standardized
-
Enhanced Alerter Hooks (New)
- Updated
alerter_failure_hookandalerter_success_hookto use structuredAlerterMessageformat - Hooks now provide better organized alerts with title, body, and metadata fields
- Full backwards compatibility with graceful fallback to string format
- Deprecation warnings when using legacy string format with
alerter.post() - Comprehensive unit tests for both AlerterMessage and string formats
- Updated
-
Bug Fixes
- Fixed unused
default_subjectvariable in SMTP Email Alerter component - Resolved mypy type errors throughout alerter components
- Improved type handling for AlerterMessage vs. string input
- Fixed docstring errors in SMTP alerter to pass darglint validation
- Fixed unused
Screenshot
Tests run
- SMTP Email Alerter can be installed and registered with server connections
- Hooks work correctly when configured
- Emails are sent with proper formatting
- Integration with OpenAI hooks works seamlessly
- Markdown formatting is correctly converted to HTML
- Type checking passes without errors
- Unit tests for alerter hooks with both AlerterMessage and legacy formats
- Backwards compatibility verified for existing hook usage
Completed TODOs
- [x] Ask @znegrin for help designing / choosing a new logo for this integration / alerter
- [x] Ask someone from product team (@schustmi ?) to upload a logo for this integration / alerter to the public s3 logos bucket.
- [x] Implement structured AlerterMessage format for alerter hooks
- [x] Add comprehensive documentation for hook usage with all alerter types
Manual Testing with Example Pipelines
All three alerters have been successfully tested with example pipelines:
-
Discord Alerter: Pipeline Run
- ✅
alerter_post_stepworking - ✅
alerter_ask_stepworking - ✅ Success hooks working
- ✅ Fixed unclosed connector warnings
- ✅ Hooks using AlerterMessage format
- ✅
-
Slack Alerter: Pipeline Run
- ✅
alerter_post_stepworking - ✅
alerter_ask_stepworking (requires bot to be invited to channel) - ✅ Custom blocks and formatting working
- ✅ Success hooks working
- ✅ Hooks using AlerterMessage format
- ✅
-
SMTP Email Alerter: Pipeline Run
- ✅ Plain text emails working
- ✅ HTML emails with default template working
- ✅ Custom HTML emails working
- ✅ Email-specific success hooks working
- ✅ Generic hooks with AlerterMessage format
Test code for all three alerters can be found in this Gist.
[!NOTE]
Other AI code review bot(s) detected
CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
📝 Walkthrough
Walkthrough
This pull request introduces SMTP email alerting capabilities into the ZenML framework. Documentation is updated to explain the new SMTP Email Alerter, its configuration, usage, and security advice. In the codebase, exception handling in failure hooks has been streamlined using standard traceback formatting and a markdown-to-HTML conversion helper was added for improved email message formatting. Additionally, a new constant for SMTP email integration is defined and several new components—including integrations, alerters, flavors, hooks, and post steps—were implemented to support the new email notification functionality.
Changes
| File(s) | Changes |
|---|---|
docs/book/.../alerters.md docs/book/.../smtp_email.md |
Updated Alerters documentation to include details on SMTP Email Alerter and added new documentation outlining its configuration, usage, and security guidelines. |
src/zenml/hooks/alerter_hooks.py src/zenml/integrations/openai/hooks/open_ai_failure_hook.py |
Revised failure hook implementations to replace Rich formatting with standard Python traceback formatting and added a helper to convert markdown to HTML. Updated model name references in OpenAI hooks. |
src/zenml/integrations/constants.py |
Added a new constant: SMTP_EMAIL = "smtp_email". |
src/zenml/integrations/smtp_email/... |
Introduced the SMTP Email integration through multiple new files, including integration classes, alerter implementation (with methods for recipient retrieval, HTML body creation, and sending alerts), flavors, hooks, and a pipeline post step. |
Sequence Diagram(s)
sequenceDiagram
participant Step as Pipeline Step
participant Hook as SMTP Email Alerter Failure Hook
participant Alerter as SMTPEmailAlerter
participant SMTP as SMTP Server
Step->>Hook: Trigger failure event
Hook->>Alerter: Build email payload & parameters
Alerter->>SMTP: Connect (with TLS/auth) and send email
SMTP-->>Alerter: Acknowledgement of sent email
Alerter-->>Hook: Return success/failure status
Poem
Oh, I'm a rabbit, hopping with glee,
New email alerts are here for all to see!
From error hooks to SMTP flow,
My code garden is set to grow.
I nibble on bugs, then bounce away—
A techy tale in every byte of day! 🐇💌
✨ Finishing Touches
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
feature/email-alerter
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreor@coderabbit ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@coderabbitai review
:white_check_mark: Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
@strickvl conflicts need a fixing :-) Just soft ping
Documentation Link Check Results
❌ Absolute links check failed There are broken absolute links in the documentation. See workflow logs for details ✅ Relative links check passed Last checked: 2025-09-03 05:02:07 UTC
@bugbot run
@bugbot run
@codex review
To use Codex here, create a Codex account and connect to github.
Closing due to staleness - feel free to open again whenever you are ready :-)