cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Way to send SQL query results from a Databricks notebook via email

faizan_111111
Databricks Partner

Hi everyone,

Iโ€™m working with a Databricks notebook where I run a SQL query using spark.sql. The query returns a small result set (mainly counts or summary values).

Once the notebook finishes running, I need to automatically send the query result from the Databricks notebook to an email (Outlook).

Iโ€™m looking for the simplest and commonly used approach to do this directly from a Databricks notebook, just a clean and reliable solution.

Any guidance or best practices would be appreciated.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Marc_Gibson96
Contributor

Hi @faizan_111111,

I would suggest setting up an email destination around a SQL Alert which should give you the ability to see returned results in the QUERY_RESULT_TABLEvariable. See: https://docs.databricks.com/aws/en/sql/user/alerts/

If this doesn't fit your use case exactly you could look at various python libraries that are designed to send emails. e.g https://docs.python.org/3/library/smtplib.html

View solution in original post

1 REPLY 1

Marc_Gibson96
Contributor

Hi @faizan_111111,

I would suggest setting up an email destination around a SQL Alert which should give you the ability to see returned results in the QUERY_RESULT_TABLEvariable. See: https://docs.databricks.com/aws/en/sql/user/alerts/

If this doesn't fit your use case exactly you could look at various python libraries that are designed to send emails. e.g https://docs.python.org/3/library/smtplib.html