You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ferruzzi (via GitHub)" <gi...@apache.org> on 2025/09/25 20:04:43 UTC

[PR] Add a new Amazon Simple Email Service Notifier [airflow]

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

   What it says in the title.
   
   Manually tested using the following Dags (you will need an AWS account and use the SES console to verify the required email addresses)
   
   ```
   from datetime import datetime, timedelta
   
   from airflow.providers.amazon.aws.hooks.ses import SesHook
   from airflow.providers.amazon.aws.notifications.ses import SesNotifier
   from airflow.sdk import task, DAG
   from airflow.sdk.definitions.deadline import DeadlineAlert, DeadlineReference, AsyncCallback
   
   PAST_DATE = datetime(1980, 8, 10, 2)
   MSG_PREFIX = "SES Testing Rnd 3:"
   
   DEFAULTS = {
       "mail_from": << REDACTED >>,
       "to": <<   REDACTED >>,
       "html_content": "message body goes here"
   }
   
   
   def _ses_callback(context):
       SesHook().send_email(**DEFAULTS, subject=f"{MSG_PREFIX} Hook as Callback -- {context['dag_run'].dag_id}")
   
   
   @task
   def send_ses_email(subject):
       SesHook().send_email(**DEFAULTS, subject=subject)
   
   
   @task.bash(task_id='sleep_task')
   def sleep_n_secs(seconds):
       return f'sleep {seconds}'
   
   
   with DAG(
       "ses_hook_via_taskflow",
       tags=["ses"]
   ):
       send_ses_email(subject=f"{MSG_PREFIX} Taskflow -- {{{{ dag_run.dag_id }}}} ")
   
   with DAG(
       "ses_callback_on_success",
       on_success_callback=_ses_callback,
       tags=["ses"],
   ):
       sleep_n_secs(1)
   
   with DAG(
       "ses_notifier_as_callback",
       on_success_callback=SesNotifier(**DEFAULTS, subject=f"{MSG_PREFIX} Sync Notifier as callback -- {{{{ dag_run.dag_id }}}} "),
       tags=["ses"],
   ):
       sleep_n_secs(1)
   
   
   with DAG(
       "ses_notifier_as_deadline",
       deadline=DeadlineAlert(
           reference=DeadlineReference.FIXED_DATETIME(PAST_DATE),
           interval=timedelta(0),
           callback=AsyncCallback(
               SesNotifier,
               kwargs={**DEFAULTS, "subject": f"{MSG_PREFIX} Async Notifier as Deadline -- {{{{ dag_run.dag_id }}}} "}
           ),
       ),
       tags=["ses"],
   ):
       sleep_n_secs(1)
   ```
   
   and proof that the emails are delivered and templates work:
   
   <img width="603" height="345" alt="image" src="https://github.com/user-attachments/assets/44053b70-61f2-453b-a1bf-5db68524a046" />
   
   
   <!--
    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.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a new Amazon Simple Email Service Notifier [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #56106:
URL: https://github.com/apache/airflow/pull/56106#discussion_r2383345747


##########
providers/amazon/src/airflow/providers/amazon/aws/hooks/ses.py:
##########
@@ -101,6 +109,64 @@ def send_email(
             custom_headers=custom_headers,
         )
 
-        return ses_client.send_raw_email(
+        return self.conn.send_raw_email(
             Source=mail_from, Destinations=recipients, RawMessage={"Data": message.as_string()}
         )
+
+    async def asend_email(

Review Comment:
   I guess it depends on personal preference :) Absolutely not blocking 👍 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a new Amazon Simple Email Service Notifier [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #56106:
URL: https://github.com/apache/airflow/pull/56106#discussion_r2382405945


##########
providers/amazon/src/airflow/providers/amazon/aws/hooks/ses.py:
##########
@@ -101,6 +109,64 @@ def send_email(
             custom_headers=custom_headers,
         )
 
-        return ses_client.send_raw_email(
+        return self.conn.send_raw_email(
             Source=mail_from, Destinations=recipients, RawMessage={"Data": message.as_string()}
         )
+
+    async def asend_email(

Review Comment:
   This comment applies to your other PR as well. Is prefixing the function with `a` a convention? I am just wondering if this is obivous to users/developers. Another alternative: prefixing with `async_`? I am not saying your way is wrong, I am unsure this would make sense for the majority of developers/users.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a new Amazon Simple Email Service Notifier [airflow]

Posted by "zachliu (via GitHub)" <gi...@apache.org>.
zachliu commented on PR #56106:
URL: https://github.com/apache/airflow/pull/56106#issuecomment-3618724890

   silly question, why aren't we `_build_email_content` as in the `SmtpNotifier`
   
   https://github.com/apache/airflow/blob/1c98f573a29d9cee3e4e0000c6fe424a2f025f83/providers/smtp/src/airflow/providers/smtp/notifications/smtp.py#L118
   
   so that they can be drop-in replacement for each other?


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a new Amazon Simple Email Service Notifier [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi merged PR #56106:
URL: https://github.com/apache/airflow/pull/56106


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a new Amazon Simple Email Service Notifier [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on PR #56106:
URL: https://github.com/apache/airflow/pull/56106#issuecomment-3628319122

   Silly answer, 🤷
   
   No particular reason.  Didn't think of it?


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a new Amazon Simple Email Service Notifier [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #56106:
URL: https://github.com/apache/airflow/pull/56106#discussion_r2383132321


##########
providers/amazon/src/airflow/providers/amazon/aws/hooks/ses.py:
##########
@@ -101,6 +109,64 @@ def send_email(
             custom_headers=custom_headers,
         )
 
-        return ses_client.send_raw_email(
+        return self.conn.send_raw_email(
             Source=mail_from, Destinations=recipients, RawMessage={"Data": message.as_string()}
         )
+
+    async def asend_email(

Review Comment:
   Yeah, that was a discussion in a previous PR and there doesn't seem to be a real concrete consensus, both ways are used.  send/asend and get/aget are common enough to say they are standard for example, but (in the other PR, for example) publish/apublish is not really common enough to know if it's "standard".



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a new Amazon Simple Email Service Notifier [airflow]

Posted by "zachliu (via GitHub)" <gi...@apache.org>.
zachliu commented on PR #56106:
URL: https://github.com/apache/airflow/pull/56106#issuecomment-3628542993

   lol cool, i'll submit a pr :stuck_out_tongue_winking_eye: 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org