balajij8
Contributor III

@SantiNath_Dey 

You can follow below

  • Python Task - You can use a Python Task within a Databricks Workflow. It's ideal if you require strict HTML format with high flexibility. Python script can query the Delta table and the full dataset can be written to a Unity Catalog Volume as CSV or Excel file. You can use smtplib or others to send the email with the summary injected in the body of the email and the file is attached directly from the Volume.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
 
fromaddr = "EMAIL address of the sender"
toaddr = "EMAIL address of the receiver"
 
# instance of MIMEMultipart
msg = MIMEMultipart()

# storing the senders email address  
msg['From'] = fromaddr

# storing the receivers email address 
msg['To'] = toaddr

# storing the subject 
msg['Subject'] = "Subject of the Mail"

# string to store the body of the mail
body = "Body_of_the_mail"

# attach the body with the msg instance
msg.attach(MIMEText(body, 'plain'))

# open the file to be sent 
filename = "File_name_with_extension"
attachment = open("Path of the file", "rb")

# instance of MIMEBase and named as p
p = MIMEBase('application', 'octet-stream')

# To change the payload into encoded form
p.set_payload((attachment).read())

# encode into base64
encoders.encode_base64(p)
 
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)

# attach the instance 'p' to instance 'msg'
msg.attach(p)

# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com', 587)

# start TLS for security
s.starttls()

# Authentication
s.login(fromaddr, "Password_of_the_sender")

# Converts the Multipart msg into a string
text = msg.as_string()

# sending the mail
s.sendmail(fromaddr, toaddr, text)

# terminating the session
s.quit()
  • Databricks Dashboard Subscriptions - Its preferred method using native Dashboards that leverages built in scheduling to distribute reports without writing any code. You can add specific users or Notification Destinations (email groups) to be notified automatically after workflow is run. Subscribers get a PDF snapshot and can optionally include tabular data from selected dashboard widgets as CSV, TSV, or Excel attachments.