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: 

Send custom emails from databricks notebook without using third party SMTP server. Would like to utilize databricks existing smtp or databricks api.

969091
New Contributor

We want to use existing databricks smtp server or if databricks api can used to send custom emails. Databricks Workflows sends email notifications on success, failure, etc. of jobs but cannot send custom emails. So we want to send custom emails to differentiate databricks environment whether email notifications are received from Dev, QA, Stage or Prod environment.

What are other possible ways to send emails? Please advise.

I have used python smtplib package to send message but got error ConnectionRefusedError: [Errno 111] Connection refused at smtpObj = smtplib.SMTP('localhost')

import smtplib

sender = 'abc@gcd.com'

receivers = ['myname@company.com']

message = """From: From Person <abc@gcd.com>

To: To Person <myname@company.com>

Subject: SMTP e-mail test

This is a test e-mail message.

"""

try:

  smtpObj = smtplib.SMTP('localhost')

  smtpObj.sendmail(sender, receivers, message)     

  print ("Successfully sent email")

except SMTPException:

  print ("Error: unable to send email")

2 REPLIES 2

LandanG
Honored Contributor
Honored Contributor

@Krishna Prasad​ Depending on the emails and how you want them to be sent, you could check out Databricks Alerts where you can send alerts depending on custom logic with a Delta table. You could use Jobs to combine the notebooks and SQL alerts to raise alerts if a notebook failed or something.

Anonymous
Not applicable

Hi @Krishna Prasad​ 

Thank you for your question! To assist you better, please take a moment to review the answer and let me know if it best fits your needs.

Please help us select the best solution by clicking on "Select As Best" if it does.

Your feedback will help us ensure that we are providing the best possible service to you.

Thank you!

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!