Availability
nauthilus_mail is available in init scripts, custom hooks, and Lua backends. It cannot be loaded by environment sources, subject sources, or actions, which run in the Policy VM. See Lua runtimes and capabilities.
SMTP/LMTP related functions
local nauthilus_mail = require("nauthilus_mail")
nauthilus_mail.send_mail
Sends an email using SMTP or LMTP protocol.
Syntax
local error = nauthilus_mail.send_mail(mail_params)
Parameters
mail_params(table): A Lua table containing the email parameters:username(string, optional): Username for authenticationpassword(string, optional): Password for authenticationfrom(string): The sender including an optional canonical nameto(table): A table of recipientsserver(string): The address of the mail serverport(number): The port number of the mail serverhelo_name(string): The HELO/LHLO namesubject(string): The subject of the messagebody(string): The body of the messagetls(boolean): Should the connection be secured aka SMTPS?starttls(boolean): Use starttls commandlmtp(boolean): Do we send with LMTP (true) or SMTP (false)?
Returns
error(string): An error message if sending fails, nil if successful
Example
local nauthilus_mail = require("nauthilus_mail")
local template = require("template")
local smtp_message = [[
Hallo,
Username: {{username}}
Account: {{account}}
...
]]
local tmpl_data = {
username = request.username, -- Might come from the request object of the calling function
account = request.account, -- Might come from the request object of the calling function
}
local mustache, err_tmpl = template.choose("mustache")
local err_email = nauthilus_mail.send_mail({
lmtp = true,
server = "10.0.0.24",
port = 24,
helo_name = "localhost.localdomain",
from = '"Sicherheitshinweis" <abuse@example.test>',
to = { request.account }, -- Might come from the request object of the calling function
subject = "Some subject",
body = mustache:render(smtp_message, tmpl_data),
})