Skip to content

mail

etl_craft.handlers.mail

Sending email as the Email settings of craft-connector.yml say.

Every email is HTML, sent from the profile's from_address under its from_name, when set, in one of two ways:

  • transport: smtp (the default): through the SMTP relay at host:port, with verified STARTTLS or implicit TLS, logged in to by auth_mode: none, password, or oauth (SMTP XOAUTH2 with a client-credentials token, for relays that refuse passwords);
  • transport: sendmail: handed to the host's sendmail program (sendmail_path), the one mailx and mail use, which delivers it through the host's own mail system.

A failure names the relay or program and what went wrong.

SMTP_TIMEOUT_SECONDS module-attribute

SMTP_TIMEOUT_SECONDS = 30.0

How long the relay may take to answer each step.

parse_recipients

parse_recipients(value: str | None, setting: str) -> list[str]

Split a |-separated address list; HandlerError naming a malformed address.

page

page(body: str) -> str

Wrap an HTML fragment in the page every email uses.

paragraph

paragraph(text: str) -> str

Return text as an escaped HTML paragraph.

send_email

send_email(config: ConnectorConfig, recipients: Sequence[str], subject: str, body_html: str) -> str | None

Send HTML email; return a partial-refusal warning, or fail with the transport and cause.

safe_subject

safe_subject(subject: str) -> str

Return a single line without control characters, capped at 200 characters.

email_tls_problem

email_tls_problem(profile: EmailProfile) -> str | None

Return unsafe or unusable TLS settings, naming the profile and the remedy.

tls_context

tls_context(profile: EmailProfile) -> ssl.SSLContext

Create a certificate and hostname verifying context using the configured CA.

open_smtp

open_smtp(profile: EmailProfile, *, timeout: float) -> smtplib.SMTP

Connect with the selected SMTP transport, refusing credentials without TLS.

sendmail_problem

sendmail_problem(profile: EmailProfile) -> str | None

Return why the profile's sendmail program cannot be run, or None.

sla_recipients

sla_recipients(config: ConnectorConfig, pipeline_recipients: Sequence[str] | None) -> list[str]

Return who hears about a pipeline's SLA: its EMAIL_RECIPIENTS, else the DAG default.

HandlerError when neither is set, naming both places.

send_sla_lapse_email

send_sla_lapse_email(config: ConnectorConfig, pipeline_recipients: Sequence[str] | None, *, pipeline_code: str, pipeline_run_id: int, sla_hours: float, elapsed_hours: float) -> None

Email that a run is past its pipeline's SLA; only when Enforce_sla is on.