Skip to content

Add emailer utilities to the SMTP provider - #74623

Merged
hussein-awala merged 2 commits into
apache:mainfrom
shivaam:codex/email-smtp-provider-only
Oct 20, 2026
Merged

hussein-awala merged 2 commits into
apache:mainfrom
shivaam:codex/email-smtp-provider-only

Conversation

@shivaam

@shivaam shivaam commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Copies airflow/utils/email.py into the SMTP provider as airflow.providers.smtp.utils.emailer, and registers it as an email backend. This is the first step of moving email out of core (#30530). Core is not changed here.

The code is the same as core's, except that imports go through common.compat and the Connection is looked up with BaseHook.get_connection. Core's tests are copied too. SmtpHook is unchanged.

Testing

Real email to a local SMTP server (Mailpit, login required), using the provider built from this branch:

  • Messages match those sent by core's code: same headers, recipients and attachments. Checked on Airflow 2.11, 3.0, 3.1, 3.2, 3.3 and main.
  • A failing task's retry and failure alerts go through this module when it is set as email_backend. Checked on Airflow 2.11, 3.1, 3.3 and main.

Next steps

  1. After a provider release that includes this module: a core PR deprecates airflow.utils.email (existing imports keep working, with a warning), points the default email_backend at this module, and raises core's minimum SMTP provider version.
  2. Have SmtpHook reuse this module's MIME helpers instead of its own copy, tidy the module, and fix get_email_address_list dropping recipients when given a generator.
  3. Remove the SES and SendGrid providers' dependency on these helpers, most likely by giving each its own small copy, so neither relies on core or on the SMTP provider.

related: #30530


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

@shivaam

shivaam commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@eladkal — could you help to an initial review? WE will have to merge this into next provider release beforew we can move things in the core.

Comment thread providers/smtp/docs/utils/legacy.rst Resolved
@shivaam
shivaam force-pushed the codex/email-smtp-provider-only branch from 5ff60a1 to f0a2130 Compare October 17, 2026 20:48
@shivaam shivaam changed the title Add legacy SMTP delivery compatibility to the provider Copy core email utilities to the SMTP provider Oct 17, 2026
Copy airflow.utils.email into airflow.providers.smtp.utils.emailer so that
core can later deprecate its email module and delegate to the provider,
once a provider release containing it is available.

The module is a copy of the core module. The only code changes are the
imports, which go through common.compat, and the Connection lookup, which
uses BaseHook.get_connection as other providers do instead of importing
airflow.models. SMTP settings still come from the [smtp] configuration
section and only the login and password from the Connection. Routing these
calls through SmtpHook instead would change behavior for existing setups,
because the hook reads all settings from the Connection and retries
differently.

Tests are copied from core, with additional edge cases. The module is
registered as an email backend.
@shivaam
shivaam force-pushed the codex/email-smtp-provider-only branch from f0a2130 to 97dcbc7 Compare October 17, 2026 21:01
@shivaam
shivaam marked this pull request as ready for review October 17, 2026 21:04
Comment thread providers/smtp/docs/utils/emailer.rst Resolved
The emailer documentation now explains what the module does and how it is
configured, without mentioning where the code came from.
@shivaam shivaam changed the title Copy core email utilities to the SMTP provider Add emailer utilities to the SMTP provider Oct 20, 2026
@hussein-awala
hussein-awala merged commit 3199497 into apache:main Oct 20, 2026
68 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

vatsrahul1001 pushed a commit that referenced this pull request Oct 27, 2026
* Add core email utilities to the SMTP provider

Copy airflow.utils.email into airflow.providers.smtp.utils.emailer so that
core can later deprecate its email module and delegate to the provider,
once a provider release containing it is available.

The module is a copy of the core module. The only code changes are the
imports, which go through common.compat, and the Connection lookup, which
uses BaseHook.get_connection as other providers do instead of importing
airflow.models. SMTP settings still come from the [smtp] configuration
section and only the login and password from the Connection. Routing these
calls through SmtpHook instead would change behavior for existing setups,
because the hook reads all settings from the Connection and retries
differently.

Tests are copied from core, with additional edge cases. The module is
registered as an email backend.

* Describe the SMTP emailer without referring to core

The emailer documentation now explains what the module does and how it is
configured, without mentioning where the code came from.
(cherry picked from commit 3199497)

Co-authored-by: Shivam Rastogi <6463385+shivaam@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants