title: How do i check if all my tasks in an airflow dag were successful?
body: <p>i need to check if all the tasks of my dag were marked as successful so that in the last task of the dag it sends an email to me to notify if all were successful or if any failed.</p>
  <p>here is a piece of code that i tried:</p>
  <pre><code>dag_runs = DagRun.find(dag_id=self.dagId)
  for dag_run in dag_runs:
                  
     if dag_run.state == 'success':
         body = f'\nHello , \nHere is the values for the pipeline {self.dagId}: \ncount of lines is {new_lines}, \nMax  date is {new_date}. \nRegards!'
     else: 
         body= f'\nHello  \nYour dag {self.dagId} has been Failed'   
  
  email_text = &quot;&quot;&quot;\
          Subject: %s    
          \nFrom: %s
          \nTo: %s
          
          \n%s
          &quot;&quot;&quot; % (subject, sent_from, self.to, body)
  
     
  try:
     smtp_server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
     smtp_server.ehlo()
     smtp_server.login(self.gmail_user, self.gmail_password)
     smtp_server.sendmail(sent_from, self.to, email_text)
     smtp_server.close()
     print (&quot;Email sent successfully!&quot;)
  
  except Exception as ex:
     print (&quot;Something went wrong….&quot;,ex)
  </code></pre>
  <p>i'm unable to check if the dag state is success. so i want to check if the state of all tasks is success</p>
  <p>thanks for the help and advice in advance.</p>