smtp
SMTP email client - connect to an SMTP server with an optional TLS flag, authenticate with username and password, send an email with From, To (string or list), Subject, and body (plain text or HTML), optional Cc and Reply-To headers, gracefully quit, send NOOP, reset with RSET, verify an address with VRFY, and expand a mailing list with EXPN.
Load with: use smtp
What this module does
smtp wraps embedder-provided __smtp_* host natives
in a clean ilusm API. It builds proper RFC-2822-style message headers
(From, To, Subject, Content-Type, MIME-Version, Cc, Reply-To) and passes
the assembled message to __smtp_send. The To field
accepts either a single address string or a list of strings.
Quick example
use smtp
# Connect (port 587 with TLS)
s = smtpc("smtp.example.com", 587, {tls: tru})
# Authenticate
s = smtpa(s, "user@example.com", "secret")
# Send plain text email
smtps(s,
"from@example.com",
"to@example.com",
"Hello from ilusm",
"This is the message body.",
nil)
# Send HTML email to multiple recipients
smtps(s,
"from@example.com",
["alice@example.com", "bob@example.com"],
"Weekly Report",
"<h1>Report</h1><p>All good.</p>",
{html: tru, cc: "manager@example.com"})
# Quit
smtpq(s)
Functions
Connection
smtpc(host, port, opts) / smtp.conn(host, port, opts)Connects to host:port. Pass {tls: tru} in opts for TLS. Default port is 25. Returns a session object.
smtpa(s, user, pass) / smtp.auth(s, user, pass)Authenticates the session. Returns the updated session.
smtpq(s) / smtp.quit(s)Sends QUIT and closes the connection.
Sending
smtps(s, from, to, subject, body, opts) / smtp.send(…)Sends an email. to may be a string or list of address strings. Options: {html: tru} for HTML body, cc for Cc address, replyto for Reply-To header.
Protocol utilities
smtpn(s)Sends SMTP NOOP (connection keep-alive).
smtpr(s)Sends SMTP RSET (reset transaction state).
smtpv(s, addr) / smtp.vrfy(s, addr)Verifies whether addr is a valid mailbox on the server.
smtpe(s, addr)Expands a mailing list name to its members via EXPN.
Notes
- Requires the host to inject
__smtp_connect,__smtp_auth,__smtp_send,__smtp_quit,__smtp_noop,__smtp_rset,__smtp_vrfy, and__smtp_expn. - Requires
txtandenc.