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

969091
Databricks Partner

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")