Abolfazlrwm opened a new pull request, #76919:
URL: https://github.com/apache/airflow/pull/76919

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   **Honor SMTP connection settings in `send_mime_email`**
   
   `send_mime_email()` currently picks up only `login` and `password` from the 
SMTP connection, while `SMTP_HOST`, `SMTP_PORT`, `SMTP_STARTTLS`, `SMTP_SSL`, 
`SMTP_TIMEOUT` and `SMTP_RETRY_LIMIT` are read exclusively from the `[smtp]` 
configuration section. A user who fully defines the `smtp_default` connection 
(host, port, TLS settings, timeout, retries) in the connection UI gets those 
values silently ignored — the email goes to whatever `[smtp]` says, which is 
rarely the same server.
   
   This patch makes the connection take precedence, using the same extra keys 
the `SmtpHook` connection form already standardizes (`disable_tls`, 
`disable_ssl`, `timeout`, `retry_limit`):
   
   - `conn.host` / `conn.port` override `SMTP_HOST` / `SMTP_PORT` when non-empty
   - extra `disable_tls` / `disable_ssl` (inverted) override `SMTP_STARTTLS` / 
`SMTP_SSL` when the key is present
   - extra `timeout` / `retry_limit` override `SMTP_TIMEOUT` / 
`SMTP_RETRY_LIMIT` when set
   - anything missing from the connection falls back to the configuration, so 
deployments relying on `[smtp]` alone see no behavior change
   
   **Provider-only, per the review feedback on #71474.** An earlier attempt 
(#71474) modified `airflow-core/src/airflow/utils/email.py` and was closed 
stale with the comment that the SMTP migration out of core 
([#30531](https://github.com/apache/airflow/issues/30531)) should be completed 
first. That migration has since been completed and the tracking issue closed, 
and core now only re-exports `send_mime_email` from 
`airflow.providers.smtp.utils.emailer`. This patch therefore applies the fix 
entirely inside the SMTP provider — no changes to `airflow-core`, and no 
newsfragment (providers regenerate their changelog at release time).
   
   Related note found while working on this: `send_email_smtp()` accepts a 
`from_email` argument but never uses it (it always uses `[smtp] 
SMTP_MAIL_FROM`; the current behavior is asserted by 
`test_send_smtp_mail_from_config_takes_precedence_over_from_email`). Left 
untouched here to keep this patch focused, but flagging it as a possible 
follow-up.
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   ^**^ Issue References
   closes: #34554
   
   ^**^ Commit Message
   Honor SMTP connection settings in send_mime_email
   
   send_mime_email() only picked up login/password from the SMTP connection 
while SMTP_HOST, SMTP_PORT, SMTP_STARTTLS, SMTP_SSL, SMTP_TIMEOUT and 
SMTP_RETRY_LIMIT came exclusively from the [smtp] configuration section, so a 
fully-defined SMTP connection was silently ignored for everything except 
credentials.
   
   The connection now takes precedence for host and port, and for the same 
extra keys SmtpHook already standardizes (disable_tls, disable_ssl, timeout, 
retry_limit). Values missing from the connection keep falling back to the 
configuration, so deployments relying on [smtp] alone are unaffected.
   
   closes: #34554
   
   ^**^ Generated-by
   - [X] Yes (GLM, code analysis, patch and unit tests co-authored with an AI 
coding assistant following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions))
   
   Generated-by: GLM
   


-- 
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