Compose
objectSends 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: ...".
- Kind Object
- Library Mail
- Category Messaging & Integrations
- Functions 2
How to get one
- Mail .properties()
- Compose
local smtp = Mail.properties(list)Returned by
Functions
send()
Section titled “send()”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
-
toEmailstring - Recipient address, or several separated by commas
-
subjectstring - Subject line
-
bodystring - Message body as HTML
-
loggingboolean optional - true to attach the log of the current step; default false
Returns
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)sendFile()
Section titled “sendFile()”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
-
toEmailstring - Recipient address, or several separated by commas
-
subjectstring - Subject line
-
bodystring - Message body as HTML
-
filestring - Path of the file in the project to attach
-
loggingboolean optional - true to attach the log of the current step; default false
Returns
Example
smtp.sendFile("alice@example.com", "Report", "<p>The report is attached.</p>", "reports/summary.pdf")