I am trying to send an email alert using the PythonOperator with email_callback
function as the python_callable
. I have an Xcom which is in the form :
(('FileName1', 'OrgName1'), ('FileName2', 'OrgName2'))
I want to print the values in the HTML content in the email alert like this:
Files Processed Successfully:
OrgName1 FileName1
OrgName2 FileName2
I know that I have to use a loop and to use a loop I have to use tag inside HTML content. I am able to get all the text outside the <script>
tag but whenever I output something from it like document.write("Hello")
, this just doesn't print anything in the email.
The code:
def email_callback(**kwargs):
task_instance = kwargs['task_instance']
body = """HELLO<script>document.write("Hello")</script>"""
send_email(
to=[
'eamil.ids'
],
subject='Batch Job Status - ' + now.strftime("%m/%d/%Y"),
html_content=body
)
AllTaskSuccess = PythonOperator (
dag=dag,
python_callable=email_callback,
trigger_rule=TriggerRule.ALL_SUCCESS,
provide_context=True,
task_id="AllTaskSuccess")
Am I missing something here?