/ DATABRICKS, CODING-SCALA

# Sending emails in Databricks by using Scala

This is going to be quite a short post, but is more intended as reference :)

Something I found to be quite interesting is sending emails through Databricks to warn me when something happened in parts of my code. After searching a bit, I came up with this code that would help me send an email:

Databricks secrets are being used, check out my other post on how to configure those: Databricks Secrets

import java.util.Properties

import java.util.Properties
import javax.mail.{Message, Session}

import scala.io.Source

val host = "<YOUR_SMTP>"
val port = "587"

def sendEmail(mailSubject: String, mailContent: String) = {
val properties = new Properties()
properties.put("mail.smtp.port", port)
properties.put("mail.smtp.auth", "true")
properties.put("mail.smtp.starttls.enable", "true")

val session = Session.getDefaultInstance(properties, null)
val message = new MimeMessage(session)