Unable to send SMTP Dag failure notifications

819 views
Skip to first unread message

Hari Priya Adusumalli

unread,
Feb 1, 2022, 11:40:43 PM2/1/22
to cloud-composer-discuss

Hi,

 

 

I need to send failure notifications from composer DAGs. I have created an app password for gmail smtp. Following is the composer config override configuration. I created the password in secret manager.

 


smtp


smtp_port


587


 


smtp_timeout


30


 


smtp_mail_from


h******@gmail.com


 


smtp_host


smtp.gmail.com


 


smtp_starttls


True


 


smtp_ssl


False


 


smtp_retry_limit


5


 


smtp_user


h******@gmail.com


 


smtp_password_secret


smtp-password


email


email_backend


airflow.utils.email.send_email_smtp


 


 


 

 

I am getting the following error after running the DAG

 

Error

2022-02-01T15:23:27.361324593Z

airflow-worker (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError mv10sm3097322pjb.45 - gsmtp', 'h*******@gmail.com')

textPayload

(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError mv10sm3097322pjb.45 - gsmtp', 'h****@gmail.com')

 

However, when I run the following python code, it sends the email successfully

 

import smtplib, ssl

smtp_server = "smtp.gmail.com"

port = 25#587# For starttls

sender_email = "h***@gmail.com"

receiver_email = "h***@gmail.com"

password = "******"#input("Type your password and press enter: ")

message = "hello"

# Create a secure SSL context

context = ssl.create_default_context()

# Try to log in to server and send email

try:

    with smtplib.SMTP(smtp_server, port) as server:

        server = smtplib.SMTP(smtp_server,port)

        server.ehlo() # Can be omitted

        server.starttls(context=context) # Secure the connection

        server.ehlo() # Can be omitted

        server.login(sender_email, password)

        server.sendmail(sender_email, receiver_email, message)

    # TODO: Send email here

except Exception as e:

    # Print any error messages to stdout

    print(e)

finally:

    server.quit()

 

I tried all possible changes I could think of, deleting secret and editing the airflow.cfg directly to set the smtp config, changing values of config each, but nothing helped . Would appreciate any help, as I am completely stuck on this.

Mohammed Tameem

unread,
Feb 1, 2022, 11:56:00 PM2/1/22
to Hari Priya Adusumalli, cloud-composer-discuss
Hi Hari,

This is one of the issues I faced while working on the same. 

If you are trying to set the SMTP configuration on Airflow running on GCP composer, then you need to use "smtp_passwprd_cmd" instead of "smtp_passwprd" as shown below :

smtp_password_cmd : echo "your password" 

The reason is, in Airflow running on Composer does not allow to change the smtp_password. 


Thanks,
Tameem

--
You received this message because you are subscribed to the Google Groups "cloud-composer-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-composer-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-composer-discuss/55ee7c24-7319-4ac4-b9c0-432336e74fcdn%40googlegroups.com.

Hari Priya Adusumalli

unread,
Feb 2, 2022, 1:31:54 AM2/2/22
to Mohammed Tameem, cloud-composer-discuss
Thanks Mohammed. I tried with the  smtp_password_cmd. I get 535 error inplace of 530. PFB the error message. Appreciate your help


  File "/opt/python3.6/lib/python3.6/smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "/opt/python3.6/lib/python3.6/smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials 38sm33300640pgm.37 - gsmtp')
[2022-02-02 06:26:26,419] {local_task_job.py:159} WARNING - State of this instance has been externally set to failed. Taking the poison pill.
[2022-02-02 06:26:26,421] {helpers.py:325} INFO - Sending Signals.SIGTERM to GPID 1325
[2022-02-02 06:26:26,554] {helpers.py:291} INFO - Process psutil.Process(pid=1325, status='terminated', exitcode=1, started='06:26:20') (1325) terminated with exit code 1
[2022-02-02 06:26:26,556] {local_task_job.py:102} INFO - Task exited with return code 1
Thanks,
Haripriya

Hari Priya Adusumalli

unread,
Feb 2, 2022, 12:13:54 PM2/2/22
to Mohammed Tameem, cloud-composer-discuss
I finally got this working. I had to 
- Disable 2-step authentication
- Enable less secure apps
- Change the password to actual gmail password rather than the app password
- Accept the Security activity couple of times, close out all chrome windows, log back in and then retrigger the DAG 
to finally get the failure notifications.

Thanks,
Haripriya
Reply all
Reply to author
Forward
0 new messages