antosdk-apps/Blogger/api/sendmail.lua

32 lines
850 B
Lua
Raw Normal View History

local data = ...
2020-05-23 20:09:01 +02:00
-- print(data.content)
local error_msg = {}
local iserror = false
2021-02-06 18:46:54 +01:00
local tmp_name = "/tmp/"..os.time(os.date("!*t"))
local file = io.open (tmp_name , "w")
if file then
file:write("From: mrsang@lxsang.me\n")
file:write("Subject: " .. data.title .. "\n")
file:write( data.content.."\n")
file:close()
for k,v in pairs(data.to) do
print("sent to:"..v)
local to = v
local cmd = 'cat ' ..tmp_name .. '| sendmail ' .. to
--print(cmd)
local r = os.execute(cmd)
if not r then
iserror = true
table.insert(error_msg, v)
print("Unable to send mail to: "..v)
end
end
2021-02-06 18:46:54 +01:00
else
iserror = true
table.insert(error_msg, "Cannot create mail file")
end
2020-05-23 20:09:01 +02:00
local result = {}
result.error = iserror
result.result = error_msg
return result