notifications — send platform notifications (email)
Method | Purpose |
|---|---|
| Send a notification |
recipients is a single email or comma-separated list (e.g. "a@x.com, b@y.com"). Set useDefaultHtmlTemplate=False to send the message body verbatim (skip the server's default HTML wrapper).
Python
# 1. Plain file path — simplest form
synutils.notifications.send(
recipients="a@x.com, b@y.com",
subject="Daily report",
message="See attached",
attachments=["/tmp/report.pdf"],
)
# 2. In-memory bytes via (filename, bytes) tuple
csv_bytes = b"id,name
1,alice
"
synutils.notifications.send(
recipients="a@x.com",
subject="Daily export",
message="Attached CSV",
attachments=[("daily.csv", csv_bytes)],
)
# 3. In-memory bytes with explicit content type — (filename, bytes, mimetype)
import json
data = {"ok": True}
synutils.notifications.send(
recipients="a@x.com",
subject="Run status",
message="See attached JSON",
attachments=[("run_status.json", json.dumps(data).encode(), "application/json")],
)
# 4. Mix of file path and in-memory content
synutils.notifications.send(
recipients="a@x.com",
subject="Job done",
message="Logs + summary",
attachments=[
"/var/log/job.log", # path
("summary.csv", b"job,seconds
foo,42
"), # bytes
],
)
# 5. File-like object (e.g. io.BytesIO) also works as the second tuple element
import io
buf = io.BytesIO()
buf.write(b"col_a,col_b
1,2
") s
ynutils.notifications.send(
recipients="a@x.com",
subject="Buffered results",
message="Attached",
attachments=[("results.csv", buf.getvalue())],
)Scala
// 1. Plain file path — simplest form (matches Python)
synutils.notifications.send(
recipients = "a@x.com, b@y.com",
subject = "Daily report",
message = "See attached",
attachments = Seq("/tmp/report.pdf")
)
// 2. In-memory bytes via tuple
val csvBytes = "id,name
1,alice
".getBytes("UTF-8")
synutils.notifications.send(
recipients = "a@x.com",
subject = "Daily export",
message = "Attached CSV",
attachments = Seq(("daily.csv", csvBytes, "text/csv"))
)
// 3. Mix of file path and in-memory content
synutils.notifications.send(
recipients = "a@x.com",
subject = "Job done",
message = "Logs + summary",
attachments = Seq(
"/var/log/job.log",
("summary.txt", "Job completed in 42s".getBytes("UTF-8"), "text/plain")
)
)
// 4. Pre-built Attachment objects also still work
synutils.notifications.send(
recipients = "a@x.com",
subject = "x", message = "y",
attachments = Seq(Attachment.fromFile("/tmp/file.csv"))
)