jensgrnb commented on issue #18495: URL: https://github.com/apache/airflow/issues/18495#issuecomment-929936713
Hello mr. Wizard) I tested my api key using curl, and that went smoothly. I noticed however that curl requires a "from_email" field, that I'm not able to set in the email_operator I use in airflow: email = EmailOperator( task_id='send_email', to='my_mail', subject='Airflow Alert', html_content=""" <h3>Email Test</h3> """, dag=dag,) I can see from the airflow provider code: https://github.com/apache/airflow/blob/main/airflow/providers/sendgrid/utils/emailer.py That the "from_email" variable seems to be used, and it default to an env var that I haven't set, so maybe the 400 response code I get is because this field is required to be not None. I can set the environment variable, but it means refreshing the whole helm chart used to deploy airflow and for such a small change I don't think it's worth it :( On Mon, 27 Sept 2021 at 17:01, Jens Grønborg ***@***.***> wrote: > Thanks for the code pointer, I'll double check the pasted api key! > > On Mon, 27 Sept 2021 at 16:51, Jarek Potiuk ***@***.***> > wrote: > >> I did not use sendgrid so I am not sure but from the code it looks like >> API_KEY is taken from connection password. I do not think host is ever >> used. You just have to make sure your connection is named >> 'sendgrid_default". You can also try env variable to test if your key is >> correct (see below): >> >> The error 400 has nothing to do with password - it is Bad request - so >> if anything this might be a bad version of sendgrid dependency, wrong >> provider, or maybe wrong format of the KEY? You need to consult sendgrid >> docs: >> >> From: >> https://github.com/apache/airflow/blob/main/airflow/providers/sendgrid/utils/emailer.py >> >> def _post_sendgrid_mail(mail_data: Dict, conn_id: str = "sendgrid_default") -> None: >> api_key = None >> try: >> conn = BaseHook.get_connection(conn_id) >> api_key = conn.password >> except AirflowException: >> pass >> if api_key is None: >> warnings.warn( >> "Fetching Sendgrid credentials from environment variables will be deprecated in a future " >> "release. Please set credentials using a connection instead.", >> PendingDeprecationWarning, >> stacklevel=2, >> ) >> api_key = os.environ.get('SENDGRID_API_KEY') >> sendgrid_client = sendgrid.SendGridAPIClient(api_key=api_key) >> response = sendgrid_client.client.mail.send.post(request_body=mail_data) >> # 2xx status code. >> if 200 <= response.status_code < 300: >> log.info( >> 'Email with subject %s is successfully sent to recipients: %s', >> mail_data['subject'], >> mail_data['personalizations'], >> ) >> else: >> log.error( >> 'Failed to send out email with subject %s, status code: %s', >> mail_data['subject'], >> response.status_code, >> ) >> >> — >> You are receiving this because you authored the thread. >> Reply to this email directly, view it on GitHub >> <https://github.com/apache/airflow/issues/18495#issuecomment-927951133>, >> or unsubscribe >> <https://github.com/notifications/unsubscribe-auth/ASQIG4TC5US2ZJHROYBROKLUECAIBANCNFSM5EV2FD7A> >> . >> Triage notifications on the go with GitHub Mobile for iOS >> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> >> or Android >> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>. >> >> > -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org