<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Serverless Compute - Python - Custom Emails via SMTP (smtplib.SMTP(host_name)) - Any alternative? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/serverless-compute-python-custom-emails-via-smtp-smtplib-smtp/m-p/131546#M49129</link>
    <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Hello Community,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;We have been trying to migrate our jobs from Classic Compute to Serverless Compute. As part of this process, we face several challenges, and this is one of them.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;We have several scenarios where we need to send an inline email via Python Code and then process to execute the rest of the code or make the job fail. We know that Databricks workflows have failure/success/threshold email functionality, but that is not helpful for my scenarios.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;In Classic Compute, I can send the emails by using&amp;nbsp;&lt;STRONG&gt;smtplib.SMTP(host_name)/&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;sendmail()&lt;/FONT&gt;&lt;/STRONG&gt;&lt;SPAN&gt;, but when it comes to the Serverless, this is not working.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Is there an alternative to sending code in-line emails when we execute any job with Serverless Compute?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#SMTP&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Custom-Email-Functionality&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Python&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Serverless-Compute&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Workflows&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Sep 2025 14:38:13 GMT</pubDate>
    <dc:creator>Ramana</dc:creator>
    <dc:date>2025-09-10T14:38:13Z</dc:date>
    <item>
      <title>Serverless Compute - Python - Custom Emails via SMTP (smtplib.SMTP(host_name)) - Any alternative?</title>
      <link>https://community.databricks.com/t5/data-engineering/serverless-compute-python-custom-emails-via-smtp-smtplib-smtp/m-p/131546#M49129</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Hello Community,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;We have been trying to migrate our jobs from Classic Compute to Serverless Compute. As part of this process, we face several challenges, and this is one of them.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;We have several scenarios where we need to send an inline email via Python Code and then process to execute the rest of the code or make the job fail. We know that Databricks workflows have failure/success/threshold email functionality, but that is not helpful for my scenarios.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;In Classic Compute, I can send the emails by using&amp;nbsp;&lt;STRONG&gt;smtplib.SMTP(host_name)/&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;sendmail()&lt;/FONT&gt;&lt;/STRONG&gt;&lt;SPAN&gt;, but when it comes to the Serverless, this is not working.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Is there an alternative to sending code in-line emails when we execute any job with Serverless Compute?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#SMTP&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Custom-Email-Functionality&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Python&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Serverless-Compute&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#Workflows&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2025 14:38:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/serverless-compute-python-custom-emails-via-smtp-smtplib-smtp/m-p/131546#M49129</guid>
      <dc:creator>Ramana</dc:creator>
      <dc:date>2025-09-10T14:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Serverless Compute - Python - Custom Emails via SMTP (smtplib.SMTP(host_name)) - Any alternative</title>
      <link>https://community.databricks.com/t5/data-engineering/serverless-compute-python-custom-emails-via-smtp-smtplib-smtp/m-p/131559#M49135</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/40873"&gt;@Ramana&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;What error do you get in serverless? Could you provide error message?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2025 15:51:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/serverless-compute-python-custom-emails-via-smtp-smtplib-smtp/m-p/131559#M49135</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-09-10T15:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Serverless Compute - Python - Custom Emails via SMTP (smtplib.SMTP(host_name)) - Any alternative</title>
      <link>https://community.databricks.com/t5/data-engineering/serverless-compute-python-custom-emails-via-smtp-smtplib-smtp/m-p/131699#M49197</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;it is neither a code issue nor an SMTP host issue, but it is purely related to Serverless Compute.&lt;/P&gt;&lt;P&gt;The same code and hostname work perfectly fine on Classic Compute but not on Serverless.&lt;/P&gt;&lt;P&gt;I don't think Databricks Serverless can recognize the third-party/client hostnames. If not, at least Databricks should have an alternative hostname to send custom emails.&lt;/P&gt;&lt;P&gt;Here is my code snippet and error details.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import email
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import traceback
import logging

# Intentionally erased all parameters before posting the code here
to_email = ""
from_email = ""
subject = "Serverless Email!"
message = "Serverless Email!"
cc_email = ""
bcc_email = ""
host_name = ""

try:
    print("Sending email - TO: " + to_email)
    msg = MIMEText(message)
    msg["Subject"] = subject
    msg["Message-id"] = email.utils.make_msgid()
    msg["From"] = from_email
    msg["To"] = to_email
    to_email = to_email.split(",")
    if cc_email:
        print("Sending email - CC: " + cc_email)
        msg["Cc"] = cc_email
        cc_email = cc_email.split(",")
        to_email = to_email + cc_email
    if bcc_email:
        # msg["Bcc"] = bcc_email
        bcc_email = bcc_email.split(",")
        to_email = to_email + bcc_email
    server = smtplib.SMTP(host_name)
    server.sendmail(from_email, to_email, msg.as_string())
    server.quit()
    print("Email Sent Successfully!")
except smtplib.SMTPException as e:
    print("Email Sending Failed.\nSMTP Exception: &amp;lt;br&amp;gt;" + str(e))
    # logging.error(e)
    traceback.print_exc()
    raise Exception(f"Exception occurred: {e}")
except Exception as e:
    print("Email Sending Failed. Exception: &amp;lt;br&amp;gt;" + str(e))
    # logging.error(e)
    traceback.print_exc()
    raise Exception(f"Exception occurred: {e}")&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Sending email - TO: 
Email Sending Failed. Exception: &amp;lt;br&amp;gt;[Errno -2] Name or service not known
Traceback (most recent call last):
  File "/home/spark-1cd5f4c8-1a9c-413f-963c-1a/.ipykernel/2497/command-8820583165797855-46947889", line 34, in &amp;lt;module&amp;gt;
    server = smtplib.SMTP(host_name)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/smtplib.py", line 341, in connect
    self.sock = self._get_socket(host, port, self.timeout)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/smtplib.py", line 312, in _get_socket
    return socket.create_connection((host, port), timeout,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/socket.py", line 828, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/socket.py", line 963, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name or service not known&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Sep 2025 19:12:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/serverless-compute-python-custom-emails-via-smtp-smtplib-smtp/m-p/131699#M49197</guid>
      <dc:creator>Ramana</dc:creator>
      <dc:date>2025-09-11T19:12:30Z</dc:date>
    </item>
  </channel>
</rss>

