shivaam commented on code in PR #75414:
URL: https://github.com/apache/airflow/pull/75414#discussion_r4377615454


##########
airflow-core/docs/howto/email-config.rst:
##########
@@ -18,80 +18,29 @@
 Email Configuration
 ===================
 
-You can configure the email that is being sent in your ``airflow.cfg``
-by setting a ``subject_template`` and/or a ``html_content_template``
-in the ``[email]`` section.
+Airflow sends task emails through the function set in ``[email] 
email_backend``. By default, email is sent
+over SMTP by the SMTP provider (``apache-airflow-providers-smtp``). To set up 
the SMTP server and its
+credentials, see :doc:`apache-airflow-providers-smtp:email-backend` and
+:doc:`apache-airflow-providers-smtp:connections/smtp`.
+
+The ``[email]`` section also sets the connection, sender and message templates 
used for any backend:
 
 .. code-block:: ini
 
   [email]
   email_backend = airflow.utils.email.send_email_smtp
+  email_conn_id = smtp_default
+  from_email = "John Doe <[email protected]>"
   subject_template = /path/to/my_subject_template_file
   html_content_template = /path/to/my_html_content_template_file
 
-Equivalent environment variables look like:
-
-.. code-block:: sh
-
-  AIRFLOW__EMAIL__EMAIL_BACKEND=airflow.utils.email.send_email_smtp
-  AIRFLOW__EMAIL__SUBJECT_TEMPLATE=/path/to/my_subject_template_file
-  AIRFLOW__EMAIL__HTML_CONTENT_TEMPLATE=/path/to/my_html_content_template_file
-
-You can configure a sender's email address by setting ``from_email`` in the 
``[email]`` section like:
-
-.. code-block:: ini
-
-  [email]
-  from_email = "John Doe <[email protected]>"
-
-Equivalent environment variables look like:
-
-.. code-block:: sh
-
-  AIRFLOW__EMAIL__FROM_EMAIL="John Doe <[email protected]>"
-
-By default, ``email_backend`` is set to 
``airflow.utils.email.send_email_smtp``, which sends email over SMTP.
-
-To configure SMTP settings, checkout the :ref:`SMTP <config:smtp>` section in 
the standard configuration.
-If you do not want to store the SMTP credentials in the config or in the 
environment variables, you can create a
-connection called ``smtp_default`` of ``Email`` type, or choose a custom 
connection name and set the ``email_conn_id`` with its name in
-the configuration & store SMTP username-password in it. Other SMTP settings 
like host, port etc always gets picked up
-from the configuration only. The connection can be of any type (for example 
'HTTP connection').
-
-.. image:: ../img/ui-dark/email_connection.png
-    :align: center
-    :alt: create email connection
-
-If you want to check which email backend is currently set, you can use 
``airflow config get-value email email_backend`` command as in
-the example below.
-
-.. code-block:: bash
-
-    $ airflow config get-value email email_backend
-    airflow.utils.email.send_email_smtp
-
-To access the task's information you use `Jinja Templating 
<http://jinja.pocoo.org/docs/dev/>`_  in your template files.
-
-For example a ``html_content_template`` file could look like this:
-
-.. code-block::
-
-  Try {{try_number}} out of {{max_tries + 1}}<br>
-  Exception:<br>{{exception_html}}<br>
-  Log: <a href="{{ti.log_url}}">Link</a><br>
-  Host: {{ti.hostname}}<br>
-  Mark success: <a href="{{ti.mark_success_url}}">Link</a><br>
+The templates use `Jinja <https://jinja.palletsprojects.com/>`_ and can access 
the task's information, for
+example ``{{ti.log_url}}``.
 
 .. note::
-    For more information on setting the configuration, see :doc:`set-config`
-
-Alternative email backends
----------------------------
 
-Instead of sending email over SMTP, you can point ``email_backend`` at an 
implementation provided by a
-community provider to send email through a third-party service's API. To use 
one, install the relevant
-provider distribution, set ``email_backend`` to the dotted path of its 
``send_email`` function, and set
-``email_conn_id`` to a connection holding the credentials it needs.
+    The functions in ``airflow.utils.email`` are deprecated and now live in

Review Comment:
   Updated the note: keep `email_backend` set to 
`airflow.utils.email.send_email_smtp`, since only the imports moved, and any 
other value, including the provider path, skips `SmtpNotifier` and reads 
`[smtp]`. The newsfragment says the same.
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by @shivaam before posting
   



##########
airflow-core/src/airflow/utils/email.py:
##########
@@ -15,327 +15,33 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-from __future__ import annotations
-
-import collections.abc
-import logging
-import os
-import re
-import smtplib
-import ssl
-from collections.abc import Iterable
-from email.mime.application import MIMEApplication
-from email.mime.multipart import MIMEMultipart
-from email.mime.text import MIMEText
-from email.utils import formatdate
-from typing import Any
-
-from airflow.configuration import conf
-from airflow.exceptions import AirflowException
-
-log = logging.getLogger(__name__)
-
-
-def send_email(
-    to: list[str] | Iterable[str],
-    subject: str,
-    html_content: str,
-    files: list[str] | None = None,
-    dryrun: bool = False,
-    cc: str | Iterable[str] | None = None,
-    bcc: str | Iterable[str] | None = None,
-    mime_subtype: str = "mixed",
-    mime_charset: str = "utf-8",
-    conn_id: str | None = None,
-    custom_headers: dict[str, Any] | None = None,
-    **kwargs,
-) -> None:
-    """
-    Send an email using the backend specified in the *EMAIL_BACKEND* 
configuration option.
-
-    :param to: A list or iterable of email addresses to send the email to.
-    :param subject: The subject of the email.
-    :param html_content: The content of the email in HTML format.
-    :param files: A list of paths to files to attach to the email.
-    :param dryrun: If *True*, the email will not actually be sent. Default: 
*False*.
-    :param cc: A string or iterable of strings containing email addresses to 
send a copy of the email to.
-    :param bcc: A string or iterable of strings containing email addresses to 
send a
-        blind carbon copy of the email to.
-    :param mime_subtype: The subtype of the MIME message. Default: "mixed".
-    :param mime_charset: The charset of the email. Default: "utf-8".
-    :param conn_id: The connection ID to use for the backend. If not provided, 
the default connection
-        specified in the *EMAIL_CONN_ID* configuration option will be used.
-    :param custom_headers: A dictionary of additional headers to add to the 
MIME message.
-        No validations are run on these values, and they should be able to be 
encoded.
-    :param kwargs: Additional keyword arguments to pass to the backend.
-    """
-    backend = conf.getimport("email", "EMAIL_BACKEND")
-    backend_conn_id = conn_id or conf.get("email", "EMAIL_CONN_ID")
-    from_email = conf.get("email", "from_email", fallback=None)
-
-    to_list = get_email_address_list(to)
-    to_comma_separated = ", ".join(to_list)
-
-    return backend(
-        to_comma_separated,
-        subject,
-        html_content,
-        files=files,
-        dryrun=dryrun,
-        cc=cc,
-        bcc=bcc,
-        mime_subtype=mime_subtype,
-        mime_charset=mime_charset,
-        conn_id=backend_conn_id,
-        from_email=from_email,
-        custom_headers=custom_headers,
-        **kwargs,
-    )
-
-
-def send_email_smtp(
-    to: str | Iterable[str],
-    subject: str,
-    html_content: str,
-    files: list[str] | None = None,
-    dryrun: bool = False,
-    cc: str | Iterable[str] | None = None,
-    bcc: str | Iterable[str] | None = None,
-    mime_subtype: str = "mixed",
-    mime_charset: str = "utf-8",
-    conn_id: str = "smtp_default",
-    from_email: str | None = None,
-    custom_headers: dict[str, Any] | None = None,
-    **kwargs,
-) -> None:
-    """
-    Send an email with html content.
-
-    :param to: Recipient email address or list of addresses.
-    :param subject: Email subject.
-    :param html_content: Email body in HTML format.
-    :param files: List of file paths to attach to the email.
-    :param dryrun: If True, the email will not be sent, but all other actions 
will be performed.
-    :param cc: Carbon copy recipient email address or list of addresses.
-    :param bcc: Blind carbon copy recipient email address or list of addresses.
-    :param mime_subtype: MIME subtype of the email.
-    :param mime_charset: MIME charset of the email.
-    :param conn_id: Connection ID of the SMTP server.
-    :param from_email: Sender email address.
-    :param custom_headers: Dictionary of custom headers to include in the 
email.
-    :param kwargs: Additional keyword arguments.
-
-    >>> send_email("[email protected]", "foo", "<b>Foo</b> bar", ["/dev/null"], 
dryrun=True)
-    """
-    smtp_mail_from = conf.get("smtp", "SMTP_MAIL_FROM")
-
-    if smtp_mail_from is not None:
-        mail_from = smtp_mail_from
-    else:
-        if from_email is None:
-            raise ValueError(
-                "You should set from email - either by smtp/smtp_mail_from 
config or `from_email` parameter"
-            )
-        mail_from = from_email
-
-    msg, recipients = build_mime_message(
-        mail_from=mail_from,
-        to=to,
-        subject=subject,
-        html_content=html_content,
-        files=files,
-        cc=cc,
-        bcc=bcc,
-        mime_subtype=mime_subtype,
-        mime_charset=mime_charset,
-        custom_headers=custom_headers,
-    )
-
-    send_mime_email(e_from=mail_from, e_to=recipients, mime_msg=msg, 
conn_id=conn_id, dryrun=dryrun)
-
-
-def build_mime_message(
-    mail_from: str | None,
-    to: str | Iterable[str],
-    subject: str,
-    html_content: str,
-    files: list[str] | None = None,
-    cc: str | Iterable[str] | None = None,
-    bcc: str | Iterable[str] | None = None,
-    mime_subtype: str = "mixed",
-    mime_charset: str = "utf-8",
-    custom_headers: dict[str, Any] | None = None,
-) -> tuple[MIMEMultipart, list[str]]:
-    """
-    Build a MIME message that can be used to send an email and returns a full 
list of recipients.
+"""Deprecated: the email utilities moved to 
:mod:`airflow.providers.smtp.utils.emailer`."""
 
-    :param mail_from: Email address to set as the email's "From" field.
-    :param to: A string or iterable of strings containing email addresses to 
set as the email's "To" field.
-    :param subject: The subject of the email.
-    :param html_content: The content of the email in HTML format.
-    :param files: A list of paths to files to be attached to the email.
-    :param cc: A string or iterable of strings containing email addresses to 
set as the email's "CC" field.
-    :param bcc: A string or iterable of strings containing email addresses to 
set as the email's "BCC" field.
-    :param mime_subtype: The subtype of the MIME message. Default: "mixed".
-    :param mime_charset: The charset of the email. Default: "utf-8".
-    :param custom_headers: Additional headers to add to the MIME message. No 
validations are run on these
-        values, and they should be able to be encoded.
-    :return: A tuple containing the email as a MIMEMultipart object and a list 
of recipient email addresses.
-    """
-    to = get_email_address_list(to)
-
-    msg = MIMEMultipart(mime_subtype)
-    msg["Subject"] = subject
-    if mail_from:
-        msg["From"] = mail_from
-    msg["To"] = ", ".join(to)
-    recipients = to
-    if cc:
-        cc = get_email_address_list(cc)
-        msg["CC"] = ", ".join(cc)
-        recipients += cc
-
-    if bcc:
-        # don't add bcc in header
-        bcc = get_email_address_list(bcc)
-        recipients += bcc
-
-    msg["Date"] = formatdate(localtime=True)
-    mime_text = MIMEText(html_content, "html", mime_charset)
-    msg.attach(mime_text)
-
-    for fname in files or []:
-        basename = os.path.basename(fname)
-        with open(fname, "rb") as file:
-            part = MIMEApplication(file.read(), Name=basename)
-            part.add_header("Content-Disposition", "attachment", 
filename=basename)
-            part["Content-ID"] = f"<{basename}>"
-            msg.attach(part)
-
-    if custom_headers:
-        for header_key, header_value in custom_headers.items():
-            msg[header_key] = header_value
-
-    return msg, recipients
-
-
-def send_mime_email(
-    e_from: str,
-    e_to: str | list[str],
-    mime_msg: MIMEMultipart,
-    conn_id: str = "smtp_default",
-    dryrun: bool = False,
-) -> None:
-    """
-    Send a MIME email.
-
-    :param e_from: The email address of the sender.
-    :param e_to: The email address or a list of email addresses of the 
recipient(s).
-    :param mime_msg: The MIME message to send.
-    :param conn_id: The ID of the SMTP connection to use.
-    :param dryrun: If True, the email will not be sent, but a log message will 
be generated.
-    """
-    smtp_host = conf.get_mandatory_value("smtp", "SMTP_HOST")
-    smtp_port = conf.getint("smtp", "SMTP_PORT")
-    smtp_starttls = conf.getboolean("smtp", "SMTP_STARTTLS")
-    smtp_ssl = conf.getboolean("smtp", "SMTP_SSL")
-    smtp_retry_limit = conf.getint("smtp", "SMTP_RETRY_LIMIT")
-    smtp_timeout = conf.getint("smtp", "SMTP_TIMEOUT")
-    smtp_user = None
-    smtp_password = None
-
-    if conn_id is not None:
-        try:
-            from airflow.models import Connection
-
-            airflow_conn = Connection.get_connection_from_secrets(conn_id)
-            smtp_user = airflow_conn.login
-            smtp_password = airflow_conn.password
-        except AirflowException:
-            pass
-    if smtp_user is None or smtp_password is None:
-        log.debug("No user/password found for SMTP, so logging in with no 
authentication.")
-
-    if not dryrun:
-        for attempt in range(smtp_retry_limit + 1):
-            log.info("Email alerting: attempt %s", str(attempt + 1))
-            try:
-                smtp_conn = _get_smtp_connection(smtp_host, smtp_port, 
smtp_timeout, smtp_ssl)
-            except smtplib.SMTPServerDisconnected:
-                if attempt == smtp_retry_limit:
-                    raise
-            else:
-                if smtp_starttls:
-                    smtp_conn.starttls(context=_get_ssl_context())
-                if smtp_user and smtp_password:
-                    smtp_conn.login(smtp_user, smtp_password)
-                log.info("Sent an alert email to %s", e_to)
-                smtp_conn.sendmail(e_from, e_to, mime_msg.as_string())
-                smtp_conn.quit()
-                break
-
-
-def get_email_address_list(addresses: str | Iterable[str]) -> list[str]:
-    """
-    Return a list of email addresses from the provided input.
-
-    :param addresses: A string or iterable of strings containing email 
addresses.
-    :return: A list of email addresses.
-    :raises TypeError: If the input is not a string or iterable of strings.
-    """
-    if isinstance(addresses, str):
-        return _get_email_list_from_str(addresses)
-    if isinstance(addresses, collections.abc.Iterable):
-        if not all(isinstance(item, str) for item in addresses):
-            raise TypeError("The items in your iterable must be strings.")
-        return list(addresses)
-    raise TypeError(f"Unexpected argument type: Received 
'{type(addresses).__name__}'.")
+from __future__ import annotations
 
+from typing import TYPE_CHECKING
 
-def _get_ssl_context() -> ssl.SSLContext | None:
-    """
-    Return the SSL context configured via the ``email.ssl_context`` option.
+from airflow.utils.deprecation_tools import add_deprecated_classes
 
-    ``"default"`` produces :func:`ssl.create_default_context`; ``"none"``
-    returns ``None`` so callers that explicitly want to skip certificate
-    validation (for example, against a self-signed SMTP server in a
-    lab environment) can still do so.
-    """
-    ssl_context_string = conf.get("email", "SSL_CONTEXT")
-    if ssl_context_string == "default":
-        return ssl.create_default_context()
-    if ssl_context_string == "none":
-        return None
-    raise RuntimeError(
-        f"The email.ssl_context configuration variable must "
-        f"be set to 'default' or 'none' and is '{ssl_context_string}."
+if TYPE_CHECKING:
+    # Lets type checkers resolve the deprecated names, which only exist at 
runtime via __getattr__.
+    from airflow.providers.smtp.utils.emailer import (
+        build_mime_message as build_mime_message,
+        get_email_address_list as get_email_address_list,
+        send_email as send_email,
+        send_email_smtp as send_email_smtp,
+        send_mime_email as send_mime_email,
     )
 
+_MOVED_TO_PROVIDER = {

Review Comment:
   Added to the PR description and the newsfragment: patch 
`airflow.providers.smtp.utils.emailer.send_mime_email` instead.
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by @shivaam before posting
   



##########
airflow-core/src/airflow/utils/email.py:
##########
@@ -15,327 +15,33 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-from __future__ import annotations
-
-import collections.abc
-import logging
-import os
-import re
-import smtplib
-import ssl
-from collections.abc import Iterable
-from email.mime.application import MIMEApplication
-from email.mime.multipart import MIMEMultipart
-from email.mime.text import MIMEText
-from email.utils import formatdate
-from typing import Any
-
-from airflow.configuration import conf
-from airflow.exceptions import AirflowException
-
-log = logging.getLogger(__name__)
-
-
-def send_email(
-    to: list[str] | Iterable[str],
-    subject: str,
-    html_content: str,
-    files: list[str] | None = None,
-    dryrun: bool = False,
-    cc: str | Iterable[str] | None = None,
-    bcc: str | Iterable[str] | None = None,
-    mime_subtype: str = "mixed",
-    mime_charset: str = "utf-8",
-    conn_id: str | None = None,
-    custom_headers: dict[str, Any] | None = None,
-    **kwargs,
-) -> None:
-    """
-    Send an email using the backend specified in the *EMAIL_BACKEND* 
configuration option.
-
-    :param to: A list or iterable of email addresses to send the email to.
-    :param subject: The subject of the email.
-    :param html_content: The content of the email in HTML format.
-    :param files: A list of paths to files to attach to the email.
-    :param dryrun: If *True*, the email will not actually be sent. Default: 
*False*.
-    :param cc: A string or iterable of strings containing email addresses to 
send a copy of the email to.
-    :param bcc: A string or iterable of strings containing email addresses to 
send a
-        blind carbon copy of the email to.
-    :param mime_subtype: The subtype of the MIME message. Default: "mixed".
-    :param mime_charset: The charset of the email. Default: "utf-8".
-    :param conn_id: The connection ID to use for the backend. If not provided, 
the default connection
-        specified in the *EMAIL_CONN_ID* configuration option will be used.
-    :param custom_headers: A dictionary of additional headers to add to the 
MIME message.
-        No validations are run on these values, and they should be able to be 
encoded.
-    :param kwargs: Additional keyword arguments to pass to the backend.
-    """
-    backend = conf.getimport("email", "EMAIL_BACKEND")
-    backend_conn_id = conn_id or conf.get("email", "EMAIL_CONN_ID")
-    from_email = conf.get("email", "from_email", fallback=None)
-
-    to_list = get_email_address_list(to)
-    to_comma_separated = ", ".join(to_list)
-
-    return backend(
-        to_comma_separated,
-        subject,
-        html_content,
-        files=files,
-        dryrun=dryrun,
-        cc=cc,
-        bcc=bcc,
-        mime_subtype=mime_subtype,
-        mime_charset=mime_charset,
-        conn_id=backend_conn_id,
-        from_email=from_email,
-        custom_headers=custom_headers,
-        **kwargs,
-    )
-
-
-def send_email_smtp(
-    to: str | Iterable[str],
-    subject: str,
-    html_content: str,
-    files: list[str] | None = None,
-    dryrun: bool = False,
-    cc: str | Iterable[str] | None = None,
-    bcc: str | Iterable[str] | None = None,
-    mime_subtype: str = "mixed",
-    mime_charset: str = "utf-8",
-    conn_id: str = "smtp_default",
-    from_email: str | None = None,
-    custom_headers: dict[str, Any] | None = None,
-    **kwargs,
-) -> None:
-    """
-    Send an email with html content.
-
-    :param to: Recipient email address or list of addresses.
-    :param subject: Email subject.
-    :param html_content: Email body in HTML format.
-    :param files: List of file paths to attach to the email.
-    :param dryrun: If True, the email will not be sent, but all other actions 
will be performed.
-    :param cc: Carbon copy recipient email address or list of addresses.
-    :param bcc: Blind carbon copy recipient email address or list of addresses.
-    :param mime_subtype: MIME subtype of the email.
-    :param mime_charset: MIME charset of the email.
-    :param conn_id: Connection ID of the SMTP server.
-    :param from_email: Sender email address.
-    :param custom_headers: Dictionary of custom headers to include in the 
email.
-    :param kwargs: Additional keyword arguments.
-
-    >>> send_email("[email protected]", "foo", "<b>Foo</b> bar", ["/dev/null"], 
dryrun=True)
-    """
-    smtp_mail_from = conf.get("smtp", "SMTP_MAIL_FROM")
-
-    if smtp_mail_from is not None:
-        mail_from = smtp_mail_from
-    else:
-        if from_email is None:
-            raise ValueError(
-                "You should set from email - either by smtp/smtp_mail_from 
config or `from_email` parameter"
-            )
-        mail_from = from_email
-
-    msg, recipients = build_mime_message(
-        mail_from=mail_from,
-        to=to,
-        subject=subject,
-        html_content=html_content,
-        files=files,
-        cc=cc,
-        bcc=bcc,
-        mime_subtype=mime_subtype,
-        mime_charset=mime_charset,
-        custom_headers=custom_headers,
-    )
-
-    send_mime_email(e_from=mail_from, e_to=recipients, mime_msg=msg, 
conn_id=conn_id, dryrun=dryrun)
-
-
-def build_mime_message(
-    mail_from: str | None,
-    to: str | Iterable[str],
-    subject: str,
-    html_content: str,
-    files: list[str] | None = None,
-    cc: str | Iterable[str] | None = None,
-    bcc: str | Iterable[str] | None = None,
-    mime_subtype: str = "mixed",
-    mime_charset: str = "utf-8",
-    custom_headers: dict[str, Any] | None = None,
-) -> tuple[MIMEMultipart, list[str]]:
-    """
-    Build a MIME message that can be used to send an email and returns a full 
list of recipients.
+"""Deprecated: the email utilities moved to 
:mod:`airflow.providers.smtp.utils.emailer`."""
 
-    :param mail_from: Email address to set as the email's "From" field.
-    :param to: A string or iterable of strings containing email addresses to 
set as the email's "To" field.
-    :param subject: The subject of the email.
-    :param html_content: The content of the email in HTML format.
-    :param files: A list of paths to files to be attached to the email.
-    :param cc: A string or iterable of strings containing email addresses to 
set as the email's "CC" field.
-    :param bcc: A string or iterable of strings containing email addresses to 
set as the email's "BCC" field.
-    :param mime_subtype: The subtype of the MIME message. Default: "mixed".
-    :param mime_charset: The charset of the email. Default: "utf-8".
-    :param custom_headers: Additional headers to add to the MIME message. No 
validations are run on these
-        values, and they should be able to be encoded.
-    :return: A tuple containing the email as a MIMEMultipart object and a list 
of recipient email addresses.
-    """
-    to = get_email_address_list(to)
-
-    msg = MIMEMultipart(mime_subtype)
-    msg["Subject"] = subject
-    if mail_from:
-        msg["From"] = mail_from
-    msg["To"] = ", ".join(to)
-    recipients = to
-    if cc:
-        cc = get_email_address_list(cc)
-        msg["CC"] = ", ".join(cc)
-        recipients += cc
-
-    if bcc:
-        # don't add bcc in header
-        bcc = get_email_address_list(bcc)
-        recipients += bcc
-
-    msg["Date"] = formatdate(localtime=True)
-    mime_text = MIMEText(html_content, "html", mime_charset)
-    msg.attach(mime_text)
-
-    for fname in files or []:
-        basename = os.path.basename(fname)
-        with open(fname, "rb") as file:
-            part = MIMEApplication(file.read(), Name=basename)
-            part.add_header("Content-Disposition", "attachment", 
filename=basename)
-            part["Content-ID"] = f"<{basename}>"
-            msg.attach(part)
-
-    if custom_headers:
-        for header_key, header_value in custom_headers.items():
-            msg[header_key] = header_value
-
-    return msg, recipients
-
-
-def send_mime_email(
-    e_from: str,
-    e_to: str | list[str],
-    mime_msg: MIMEMultipart,
-    conn_id: str = "smtp_default",
-    dryrun: bool = False,
-) -> None:
-    """
-    Send a MIME email.
-
-    :param e_from: The email address of the sender.
-    :param e_to: The email address or a list of email addresses of the 
recipient(s).
-    :param mime_msg: The MIME message to send.
-    :param conn_id: The ID of the SMTP connection to use.
-    :param dryrun: If True, the email will not be sent, but a log message will 
be generated.
-    """
-    smtp_host = conf.get_mandatory_value("smtp", "SMTP_HOST")
-    smtp_port = conf.getint("smtp", "SMTP_PORT")
-    smtp_starttls = conf.getboolean("smtp", "SMTP_STARTTLS")
-    smtp_ssl = conf.getboolean("smtp", "SMTP_SSL")
-    smtp_retry_limit = conf.getint("smtp", "SMTP_RETRY_LIMIT")
-    smtp_timeout = conf.getint("smtp", "SMTP_TIMEOUT")
-    smtp_user = None
-    smtp_password = None
-
-    if conn_id is not None:
-        try:
-            from airflow.models import Connection
-
-            airflow_conn = Connection.get_connection_from_secrets(conn_id)
-            smtp_user = airflow_conn.login
-            smtp_password = airflow_conn.password
-        except AirflowException:
-            pass
-    if smtp_user is None or smtp_password is None:
-        log.debug("No user/password found for SMTP, so logging in with no 
authentication.")
-
-    if not dryrun:
-        for attempt in range(smtp_retry_limit + 1):
-            log.info("Email alerting: attempt %s", str(attempt + 1))
-            try:
-                smtp_conn = _get_smtp_connection(smtp_host, smtp_port, 
smtp_timeout, smtp_ssl)
-            except smtplib.SMTPServerDisconnected:
-                if attempt == smtp_retry_limit:
-                    raise
-            else:
-                if smtp_starttls:
-                    smtp_conn.starttls(context=_get_ssl_context())
-                if smtp_user and smtp_password:
-                    smtp_conn.login(smtp_user, smtp_password)
-                log.info("Sent an alert email to %s", e_to)
-                smtp_conn.sendmail(e_from, e_to, mime_msg.as_string())
-                smtp_conn.quit()
-                break
-
-
-def get_email_address_list(addresses: str | Iterable[str]) -> list[str]:
-    """
-    Return a list of email addresses from the provided input.
-
-    :param addresses: A string or iterable of strings containing email 
addresses.
-    :return: A list of email addresses.
-    :raises TypeError: If the input is not a string or iterable of strings.
-    """
-    if isinstance(addresses, str):
-        return _get_email_list_from_str(addresses)
-    if isinstance(addresses, collections.abc.Iterable):
-        if not all(isinstance(item, str) for item in addresses):
-            raise TypeError("The items in your iterable must be strings.")
-        return list(addresses)
-    raise TypeError(f"Unexpected argument type: Received 
'{type(addresses).__name__}'.")
+from __future__ import annotations
 
+from typing import TYPE_CHECKING
 
-def _get_ssl_context() -> ssl.SSLContext | None:
-    """
-    Return the SSL context configured via the ``email.ssl_context`` option.
+from airflow.utils.deprecation_tools import add_deprecated_classes
 
-    ``"default"`` produces :func:`ssl.create_default_context`; ``"none"``
-    returns ``None`` so callers that explicitly want to skip certificate
-    validation (for example, against a self-signed SMTP server in a
-    lab environment) can still do so.
-    """
-    ssl_context_string = conf.get("email", "SSL_CONTEXT")
-    if ssl_context_string == "default":
-        return ssl.create_default_context()
-    if ssl_context_string == "none":
-        return None
-    raise RuntimeError(
-        f"The email.ssl_context configuration variable must "
-        f"be set to 'default' or 'none' and is '{ssl_context_string}."
+if TYPE_CHECKING:
+    # Lets type checkers resolve the deprecated names, which only exist at 
runtime via __getattr__.
+    from airflow.providers.smtp.utils.emailer import (
+        build_mime_message as build_mime_message,
+        get_email_address_list as get_email_address_list,
+        send_email as send_email,
+        send_email_smtp as send_email_smtp,
+        send_mime_email as send_mime_email,
     )
 
+_MOVED_TO_PROVIDER = {
+    "send_email": "airflow.providers.smtp.utils.emailer.send_email",
+    "send_email_smtp": "airflow.providers.smtp.utils.emailer.send_email_smtp",
+    "build_mime_message": 
"airflow.providers.smtp.utils.emailer.build_mime_message",
+    "send_mime_email": "airflow.providers.smtp.utils.emailer.send_mime_email",
+    "get_email_address_list": 
"airflow.providers.smtp.utils.emailer.get_email_address_list",
+}
 
-def _get_smtp_connection(host: str, port: int, timeout: int, with_ssl: bool) 
-> smtplib.SMTP:
-    """
-    Return an SMTP connection to the specified host and port, with optional 
SSL encryption.
-
-    :param host: The hostname or IP address of the SMTP server.
-    :param port: The port number to connect to on the SMTP server.
-    :param timeout: The timeout in seconds for the connection.
-    :param with_ssl: Whether to use SSL encryption for the connection.
-    :return: An SMTP connection to the specified host and port.
-    """
-    if not with_ssl:
-        return smtplib.SMTP(host=host, port=port, timeout=timeout)
-    return smtplib.SMTP_SSL(host=host, port=port, timeout=timeout, 
context=_get_ssl_context())
-
-
-def _get_email_list_from_str(addresses: str) -> list[str]:
-    """
-    Extract a list of email addresses from a string.
-
-    The string can contain multiple email addresses separated
-    by any of the following delimiters: ',' or ';'.
+# Keeps "from airflow.utils.email import *" importing the deprecated names.
+__all__ = list(_MOVED_TO_PROVIDER)
 
-    :param addresses: A string containing one or more email addresses.
-    :return: A list of email addresses.
-    """
-    pattern = r"\s*[,;]\s*"
-    return re.split(pattern, addresses)
+add_deprecated_classes({__name__: _MOVED_TO_PROVIDER}, package=__name__)

Review Comment:
   Done. The warning now says the Connection is looked up with 
`BaseHook.get_connection` and that settings come from the Task SDK 
configuration, so a runtime `conf.set()` is not seen.
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by @shivaam before posting
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to