Skip to content

Sends email through the SMTP server configured with Mail.properties. Every send opens a new connection, sends one HTML mail from the configured user and closes the connection again. Errors (connection refused, login rejected, invalid address, missing attachment file) are raised as "Error caught while trying to send e-mail: ...".

How to get one

  1. Mail .properties()
  2. Compose
local smtp = Mail.properties(list)

Functions

  • send self Sends an email from the configured user.
  • sendFile self Sends an HTML email with one file from the project attached.
smtp.send(toEmail: string, subject: string, body: string)→selfsmtp.send(toEmail: string, subject: string, body: string, logging: boolean)→self

Sends an email from the configured user. The body is sent as HTML (text/html, UTF-8), so use `<br>` or `<p>` for line breaks; plain newlines are collapsed by mail clients. The recipient argument takes one address or several separated by commas ("a@x.com, b@x.com"); there is no cc, bcc or reply-to. With logging true the log of the current step is attached as a text file, which is handy for failure notifications. Returns the Compose object when the server accepted the mail, which does not guarantee delivery.

Parameters

toEmail string
Recipient address, or several separated by commas
subject string
Subject line
body string
Message body as HTML
logging boolean optional
true to attach the log of the current step; default false

Returns

self chainable The smtp itself, so calls can be chained.

Example

local smtp = Mail.properties({
["mail.smtp.host"] = "smtp.example.com",
["mail.smtp.port"] = 587,
["mail.smtp.auth"] = "true",
["mail.smtp.starttls.enable"] = "true",
user = "bot@example.com",
password = secret("mail_password"),
})
smtp.send("alice@example.com, bob@example.com", "Nightly run finished", "<p>All <b>42</b> checks passed.</p>")
smtp.send("qa-team@example.com", "Nightly run FAILED", "See the attached log.", true)
smtp.sendFile(toEmail: string, subject: string, body: string, file: string)→selfsmtp.sendFile(toEmail: string, subject: string, body: string, file: string, logging: boolean)→self

Sends an HTML email with one file from the project attached. Recipients, body and errors work as in send. The file is attached as it is on disk (a missing file raises an error), under its own file name. With logging true the step log is attached as well.

Parameters

toEmail string
Recipient address, or several separated by commas
subject string
Subject line
body string
Message body as HTML
file string
Path of the file in the project to attach
logging boolean optional
true to attach the log of the current step; default false

Returns

self chainable The smtp itself, so calls can be chained.

Example

smtp.sendFile("alice@example.com", "Report", "<p>The report is attached.</p>", "reports/summary.pdf")