(08.04.2023, 13:58)Dré Wrote: Is it also possible to get a notification when it restarts?
Code:
-- Common Function
function mail(to, subject, message)
-- make sure these settings are correct
local settings = {
-- "from" field, only e-mail must be specified here
from = 'servis@servis.com',
-- smtp username
user = 'username',
-- smtp password
password = 'password',
-- smtp server
server = 'smtp.myserver.com',
-- smtp server port
port = 25,
-- enable ssl, required for gmail smtp
-- secure = 'sslv23',
}
-- port 465
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
-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
['Content-type'] = 'text/html; charset=utf-8',
},
body = message
})
-- fixup from field
settings.from = '<' .. tostring(settings.from) .. '>'
settings.rcpt = to
return smtp.send(settings)
end
Code:
-- Init Script
mail( 'mymail@mail.com', 'Restart LogicMachine', 'my message body')
Code:
-- Sync before reboot
os.execute('sync')