Created
February 27, 2019 19:32
-
-
Save mdivk/53a6988dcd40a1f913607250174da65e to your computer and use it in GitHub Desktop.
Airflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#credit to mholtzscher: https://gist.github.com/mholtzscher/9648cfd27769d1df6a6ed855fdd7bd7a | |
from airflow.models import DAG | |
from airflow.operators.email_operator import EmailOperator | |
from airflow.operators.python_operator import PythonOperator | |
from datetime import datetime | |
from tempfile import NamedTemporaryFile | |
dag = DAG( | |
"email_example", | |
description="Sample Email Example with File attachments", | |
schedule_interval="@daily", | |
start_date=datetime(2018, 12, 7), | |
catchup=False, | |
) | |
def build_email(**context): | |
with NamedTemporaryFile(mode='w+', suffix=".txt") as file: | |
file.write("Hello World") | |
email_op = EmailOperator( | |
task_id='send_email', | |
to="[email protected]", | |
subject="Test Email Please Ignore", | |
html_content=None, | |
files=[file.name], | |
) | |
email_op.execute(context) | |
email_op_python = PythonOperator( | |
task_id="python_send_email", python_callable=build_email, provide_context=True, dag=dag | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment