How to send email or SMS messages from Databricks notebooks

Learn how to send an email from your Databricks notebook.

Written by Adam Pavlacka

Last published at: May 17th, 2022

You may need to send a notification to a set of recipients from a Databricks notebook. For example, you may want to send email based on matching business rules or based on a command’s success or failure. This article describes two approaches to sending email or SMS messages from a notebook. Both examples use Python notebooks:

Send email or SMS messages from a notebook using Amazon SNS

This approach requires that you have an Amazon Simple Notification Service (SNS) article to send the notification to. Recipients who are subscribed to the SNS article will receive the email or SMS notification.



You may need to install boto3, a Python library for working with Amazon AWS:


pip install boto3

Add the following Python commands to your notebook, replacing <sample values> with your own:


# Import the boto3 client
import boto3

# Set the AWS region name, retrieve the access key & secret key from dbutils secrets.
# For information about how to store the credentials in a secret, see
AWS_REGION = "<region-name>"
ACCESS_KEY = dbutils.secrets.get('<scope-name>','<access-key>')
SECRET_KEY = dbutils.secrets.get('<scope-name>','<secret-key>')

#Create the boto3 client with the region name, access key and secret keys.
client = boto3.client('sns',region_name=AWS_REGION,

# Add email subscribers
for email in list_of_emails:
        Endpoint=email  # <-- email address who'll receive an email.

# Add phone subscribers
for number in list_of_phone_numbers:
        Endpoint=number  # <-- phone numbers who'll receive SMS.

# Send message to the SNS article using publish method.
response = client.publish(
Message="Hello From Databricks..",
Subject='Email Notification from Databricks..',

Send email from a notebook using Amazon SES

This example notebook demonstrates how to send an email message that includes HTML content and a file attachment, using Amazon Simple Email Service (SES).

Example Send email notebook

Review the Send email notebook.

Was this article helpful?