esi-smtp
A library for sending a mail using the simple mail transfer protocol via socket.smtp, wincurl or luacurl.
Changes
version | date | description |
---|---|---|
1.0.1 |
2020-12-08 |
TFS code synchronisation |
1.1.0 |
2021-06-10 |
Implemented mail attachments for LCURL |
Available functions
All functions have to be called according to the ESI standard, using colons, e.g. lib:FUNCTIONNAME(params)
Documentation
SETMAILSERVERACCOUNT
SETMAILSERVERACCOUNT(self,user,pw,server,port,sendmode,ssl,sslurl)
Mandatory function to setup the sending requirements
SETMAILINGLIST
SETMAILINGLIST(self,name,rcps)
Register a mailing list that can be used using lib:SENDLIST
SEND
SEND(self,rcps,subj,content[,attachments])
The executing function to send emails
Usage
local respone, error = lib:SEND("myname@mydomaing.com", "My subject", "<p>My HTML code </p>")
if error then return error else return response end
LCURL: Sending mails with attachments
When using LCURL to send mails, starting from version 1.1.0 you can attach and/or embed file into mails.
lib:SEND accepts a 4th parameter "attachments" when sendmode is set to LCURL in SETMAILSERVERACCOUNT.
Attachments are defined as lua object with following structure
name | description |
---|---|
filename |
The name of the file including extension |
mime |
The MIME which defines the data format of the attachment according to RFC822 |
encoding |
Defines how the content got encoded |
content |
The content of the attachment |
local attachments = {}
table.insert(attachments, {
filename = "example.png",
mime = "image/png",
encoding = "base64",
content = myB64String
})
table.insert(attachments, {
filename = "systemlogs.json",
mime = "application/json",
content = json.encode(syslib.getlogs(syslib.now() - 10 * 60 * 1000 , syslib.now()))
})
local html =
[[<html>
<body>
<div>
<p>This is an automated message</p>
{ width=1000 height=700 }
<p>Cheers, Robot</p>
</div>
</body>
</html>]]
local res, err = lib:SEND("myname@mydomaing.com", "My subject", html, attachments)