Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smtp email user and password deprecated config removal #41539

Merged
merged 4 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2213,21 +2213,6 @@ smtp:
type: string
example: ~
default: "False"
smtp_user:
description: |
Username to authenticate when connecting to smtp server.
version_added: ~
type: string
example: "airflow"
default: ~
smtp_password:
description: |
Password to authenticate when connecting to smtp server.
version_added: ~
type: string
sensitive: true
example: "airflow"
default: ~
smtp_port:
description: |
Defines the port number on which Airflow connects to the SMTP server to send email notifications.
Expand Down
2 changes: 0 additions & 2 deletions airflow/config_templates/unit_tests.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ celery_logging_level = INFO

[smtp]
# Used as default values for SMTP unit tests
smtp_user = airflow
smtp_password = airflow
smtp_mail_from = [email protected]

[api]
Expand Down
15 changes: 2 additions & 13 deletions airflow/utils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import os
import smtplib
import ssl
import warnings
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
Expand All @@ -32,7 +31,7 @@
import re2

from airflow.configuration import conf
from airflow.exceptions import AirflowConfigException, AirflowException, RemovedInAirflow3Warning
from airflow.exceptions import AirflowException

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -255,17 +254,7 @@ def send_mime_email(
except AirflowException:
pass
if smtp_user is None or smtp_password is None:
warnings.warn(
"Fetching SMTP credentials from configuration variables will be deprecated in a future "
"release. Please set credentials using a connection instead.",
RemovedInAirflow3Warning,
stacklevel=2,
)
try:
smtp_user = conf.get("smtp", "SMTP_USER")
smtp_password = conf.get("smtp", "SMTP_PASSWORD")
except AirflowConfigException:
log.debug("No user/password found for SMTP, so logging in with no authentication.")
log.debug("No user/password found for SMTP, so logging in with no authentication.")

if not dryrun:
for attempt in range(1, smtp_retry_limit + 1):
Expand Down
4 changes: 0 additions & 4 deletions docs/apache-airflow/howto/email-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ You can use the default airflow SMTP backend to send email with SendGrid
smtp_host=smtp.sendgrid.net
smtp_starttls=False
smtp_ssl=False
smtp_user=apikey
smtp_password=<generated-api-key>
smtp_port=587
smtp_mail_from=<your-from-email>

Expand All @@ -108,8 +106,6 @@ Equivalent environment variables looks like
AIRFLOW__SMTP__SMTP_HOST=smtp.sendgrid.net
AIRFLOW__SMTP__SMTP_STARTTLS=False
AIRFLOW__SMTP__SMTP_SSL=False
AIRFLOW__SMTP__SMTP_USER=apikey
AIRFLOW__SMTP__SMTP_PASSWORD=<generated-api-key>
AIRFLOW__SMTP__SMTP_PORT=587
AIRFLOW__SMTP__SMTP_MAIL_FROM=<your-from-email>

Expand Down
1 change: 1 addition & 0 deletions newsfragments/41539.significant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed deprecated ``smtp_user`` and ``smtp_password`` configuration parameters from ``smtp`` section. Please use smtp connection (``smtp_default``).
1 change: 0 additions & 1 deletion tests/core/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,6 @@ def test_sensitive_values():
("database", "sql_alchemy_conn"),
("core", "fernet_key"),
("core", "internal_api_secret_key"),
("smtp", "smtp_password"),
("webserver", "secret_key"),
("secrets", "backend_kwargs"),
("sentry", "sentry_dsn"),
Expand Down
11 changes: 1 addition & 10 deletions tests/utils/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import pytest

from airflow.configuration import conf
from airflow.exceptions import RemovedInAirflow3Warning
from airflow.utils import email
from tests.test_utils.config import conf_vars

Expand Down Expand Up @@ -217,22 +216,14 @@ def test_send_mime_airflow_config(self, mock_smtp, mock_smtp_ssl, monkeypatch):
monkeypatch.delenv("AIRFLOW_CONN_SMTP_DEFAULT", raising=False)
mock_smtp.return_value = mock.Mock()
msg = MIMEMultipart()
with pytest.warns(
RemovedInAirflow3Warning,
match="Fetching SMTP credentials from configuration variables.*deprecated",
):
email.send_mime_email("from", "to", msg, dryrun=False)
email.send_mime_email("from", "to", msg, dryrun=False)
mock_smtp.assert_called_once_with(
host=conf.get("smtp", "SMTP_HOST"),
port=conf.getint("smtp", "SMTP_PORT"),
timeout=conf.getint("smtp", "SMTP_TIMEOUT"),
)
assert not mock_smtp_ssl.called
assert mock_smtp.return_value.starttls.called
mock_smtp.return_value.login.assert_called_once_with(
conf.get("smtp", "SMTP_USER"),
conf.get("smtp", "SMTP_PASSWORD"),
)
mock_smtp.return_value.sendmail.assert_called_once_with("from", "to", msg.as_string())
assert mock_smtp.return_value.quit.called

Expand Down