27.03.2024, 09:27
Hi,
What is wrong ?
What is wrong ?
Code:
-- user function library
function mail(to, subject, message)
-- make sure these settings are correct
local settings = {
-- "from" field, only e-mail must be specified here
from = 'XXXXXX@XXXXXX.COM',
-- smtp username
user = 'XXXXXX@XXXXXX.COM',
-- smtp password
password = 'XXXXXX',
-- smtp server
server = 'smtp.office365.com',
-- smtp server port
port = 587,
-- enable tls
secure = 'tlsv1.3',
-- use STARTTLS mode
starttls = true
}
local smtp = require('socket.smtp')
if type(to) ~= 'table' then
to = { to }
end
for index, email in ipairs(to) do
to[ index ] = '<' .. tostring(email) .. '>'
end
-- fixup from field
local from = '<' .. tostring(settings.from) .. '>'
-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
['From'] = from,
['Content-type'] = 'text/html; charset=utf-8',
},
body = message
})
settings.from = from
settings.rcpt = to
log("send email:")
log(settings)
return smtp.send(settings)
end