Hi,
I would like to know if it possible to send the content of a text file (for instance a log file) within an email, via a Blockly script?
Thanks in advance.
Julien
Send content of a file via Blockly
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Send content of a file via Blockly
I don't know if it is possible with blockly but in dzVents it would look like
Code: Select all
-- Email text from OS file
return {
on = {
timer = {"every minute" }
},
execute = function(dz)
local function linesFrom(file)
if not dz.utils.fileExists(file) then return 0 end
allLines = {}
for line in io.lines(file) do
allLines[#allLines + 1] = line:gsub('#','บบ') -- the # character is seen as a field separator by domoticz so we need to replace it
end
return allLines
end
local emailaddress = "[email protected]"
local emailSubject = "testSubject"
local osFile = "/etc/init.d/domoticz.sh" -- full qualified filename
local allLines = linesFrom(osFile)
if allLines ~= 0 then
local maxLines = 1000 -- Tested with 1000 lines but YMMV
for i = 0, #allLines, maxLines do -- big steps (at least 1 step)
dz.email(subject,table.concat(allLines,"\\n",i +1,math.min( i + maxLines,#allLines)),emailaddress) -- When more then maxLines split in multiple Emails
end
else
dz.email(emailSubject,"Non existent file",emailaddress) -- Wrong filename ??
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest