Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example Email Operator Usage with Attachment
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(
description="Sample Email Example with File attachments",
start_date=datetime(2018, 12, 7),
def build_email(**context):
with NamedTemporaryFile(mode='w+', suffix=".txt") as file:
file.write("Hello World")
email_op = EmailOperator(
subject="Test Email Please Ignore",
email_op_python = PythonOperator(
task_id="python_send_email", python_callable=build_email, provide_context=True, dag=dag
Copy link

touseefzaki commented Feb 25, 2020

when I try to use the EmailOperator, I am getting below error
ERROR - No module named 'email_backend = airflow'

May I know What I am missing in my implementation

Copy link

Welt0n commented Mar 8, 2021

You probably need to config it in airflow.cfg, it is in your airflow_home directory

Copy link

srivallivagdevi commented Apr 20, 2021

What are the configuration changes that are to be done? No errors and no mail

Copy link

nandhan2047 commented Jun 2, 2021

what is the alternate for this as EmailOperator is gone now.

Copy link

mmunarriz commented Jul 6, 2021

PendingDeprecationWarning: Fetching SMTP credentials from configuration variables will be deprecated in a future release. Please set credentials using a connection instead.

Copy link

novadejamesng commented Mar 25, 2022

In airflow.cfg, use this:
email_backend =
so that you can use this:
from airflow.operators.email_operator import EmailOperator

Copy link

manishkmbl0 commented Jul 28, 2022

can we attache file in email from GCS any bucket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment