28.07.2020, 15:03
(This post was last modified: 29.07.2020, 07:03 by Erwin van der Zwart.)
Hi,
Here is a improved version of your script, sorry i couldn't ignore if else then's (:
It also performs a regex on your mail addresses to be sure they are valid. (~="" does not say anything)
BR,
Erwin
Here is a improved version of your script, sorry i couldn't ignore if else then's (:
It also performs a regex on your mail addresses to be sure they are valid. (~="" does not say anything)
Code:
alarm = grp.getvalue('10/0/31')
if alarm then
email1 = grp.getvalue('32/6/1')
email2 = grp.getvalue('32/6/2')
email3 = grp.getvalue('32/6/3')
emails = {}
if email1:match('[%w]*[%p]*%@+[%w]*[%.]?[%w]*') then table.insert(emails, email1) end
if email2:match('[%w]*[%p]*%@+[%w]*[%.]?[%w]*') then table.insert(emails, email2) end
if email3:match('[%w]*[%p]*%@+[%w]*[%.]?[%w]*') then table.insert(emails, email3) end
if #emails > 0 then
mail(emails, 'MAJA valvekeskuse alarm', 'Tere! <br><br>Valvekeskuse poolt on tuvastatud MAJA häire! Palun vaadake täpsemalt visualiseeringust.<br><br><br><i>See email on genereeritud automaatikasüsteemi poolt. Palun mitte sellele emailile vastata!')
else
log('no valid mail adresses found')
end
end
Erwin