Module sendmail
Functions
sendmail (from, to, smtp_server, message, options) | Send mail. |
sendmail (params) | Send mail. |
Tables
FROM | a table describe FROM header. |
TO | a table describe TO headers. |
SERVER | a table describe smtp server. |
SSL | a table describe SSL securety options. |
MESSAGE | a table describe message. |
SUBJECT | a table describe subject. |
TEXT | a table describe text part in message. |
FILE | a table describe attached file in message. |
OPTIONS | a table describe sendmail options. |
CURL | a table describe the cURL IO backend |
SENDPARAMS | Send mail params as single table. |
Fields
DEFAULT_CHARSET | Default charset |
DEFAULT_ENCODE | Default encoding |
Functions
- sendmail (from, to, smtp_server, message, options)
-
Send mail.
Parameters:
- from string or FROM
- to string or TO
- smtp_server string or SERVER
- message string or MESSAGE
- options optional OPTIONS
Returns:
- int or nil number of the sent messages
- string error message
Usage:
sendmail('me@host', 'to@host', 'host', {'test', 'hello'})
- sendmail (params)
-
Send mail.
Parameters:
- params SENDPARAMS
Returns:
- int or nil number of the sent messages
- string error message
Usage:
sendmail('me@host', 'to@host', 'host', {'test', 'hello'})
Tables
- FROM
-
a table describe FROM header.
Fields:
- TO
-
a table describe TO headers.
Fields:
- title optional string title used in header (or first value of table)
- address string or {string,...} email address
- charset optional string title charset
- encode optional string ecoding used for title
- SERVER
-
a table describe smtp server.
Fields:
- address string
- port number or string (default 25 and 465 if you set `ssl` options)
- user string
- password string
- ssl SSL, boolean, string or opaque securety options. `true` mean use default options. Also you can pass protocol name as string. (required `LuaSec` module). opaque value used with custom `create` function.
- create function constructor for creating socket. If `ssl` option is provided then it pass to `create` function without any changes.
- SSL
-
a table describe SSL securety options.
For more information see documentation for `LuaSec` module.
Library use similar mechanism to find CA file as in cURL library.
Library use environment variables to find CA file.
On Windows library also search in system directory. (required `lua-path` module)
For more information see SSL Certificate Verification
for cURL library.
Fields:
- protocol string or table (default "tlsv1")
- verify string or table (default {"peer", "fail_if_no_peer_cert"})
- options string or table (default {"all"})
- cafile optional string
- capath optional string
Usage:
ssl = {verify = "none"} -- ignore sert
- MESSAGE
-
a table describe message.
Fields:
- subject string or SUBJECT (or first value of table)
- text string or TEXT if no mime_type then 'text/plain' used (or second value of table)
- html string or TEXT if no mime_type then 'text/html' used
- file string, FILE or {FILE,...} path, file or array of files
Usage:
msg = {'this is subject'} msg = {'this is subject';'this is text'} msg = {subject = 'this is subject';'this is text'} msg = {'this is subject';text='this is text'} msg = {'subject', 'text', file = 'path/to/file'}
- SUBJECT
-
a table describe subject.
Fields:
- TEXT
-
a table describe text part in message.
Fields:
- FILE
-
a table describe attached file in message.
One of fields path, data, file are required.
If no name and path is setted then name sets to basename of file.
Fields:
- name string attachment's name
- path optional string surce file path
- data optional string content of attachment
- file optional file opened file handle (io.open in binary mode)
- source optional ltn12.source source of file content
- charset optional string
- encode optional string
- mime_type optional string Default 'application/octet-stream'
- disposition optional string Default 'attachment'
- headers optional table
- OPTIONS
-
a table describe sendmail options.
Fields:
- confirm_sending boolean
- CURL
-
a table describe the cURL IO backend
Fields:
- async optional boolean if set to true then sendmail just init/create a cURL easy handle and returns it. So it wil be possible to use this handle to perform async IO using cURL multi handle. User code responsible for close this handle.
- handle cURL::easy pass existing cURL easy handle. sendmail does not close this handle. So it will be possible to reuse the same easy handle to send multiple emails.
- SENDPARAMS
-
Send mail params as single table.
Fields: