Send only email notification

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
elgringo
Posts: 102
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Send only email notification

Post by elgringo »

I want to send a notify only via email since it is long and contains multiple lines. When using the notify there is an option to send a system:

Code: Select all

NSS_GOOGLE_CLOUD_MESSAGING, NSS_HTTP, NSS_KODI, NSS_LOGITECH_MEDIASERVER, NSS_NMA,NSS_PROWL, NSS_PUSHALOT, NSS_PUSHBULLET, NSS_PUSHOVER, NSS_PUSHSAFER, NSS_TELEGRAM
However there is no 'NSS_EMAIL'. Is it possible to send a notify only via email? I know there is a email command but rather want to use the notify function to prevent storing the email addresses at multiple places.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Send only email notification

Post by waaren »

elgringo wrote: Thursday 29 November 2018 17:40 I want to send a notify only via email since it is long and contains multiple lines. When using the notify there is an option to send a system
However there is no 'NSS_EMAIL'. Is it possible to send a notify only via email? I know there is a email command but rather want to use the notify function to prevent storing the email addresses at multiple places.
the Domoticz notification system differs from the email system. In the notification settings the addressee is set and in the Email system the sender.
However there are at least two ways to overcome this for your requirement.
The first method is to ask domoticz for the senders address and store that in persistent data and use that as mailTo information. This can be done at either script persistent data level or on global persistent data level.
The other "dirty" method is to use "root@localhost" as mailTo address. This generates an error in the maildelivery susbsystem but (at least in gmail) the endresult is that the Email lands in the inbox of the in domoticz defined sender.

See below for an example dzVents script.

Code: Select all

local httpResponse = "settingsFromDomoticz" 

return {
            on      =   { timer         = { "every minute" },
                            httpResponses   = { httpResponse }}, 
            
            data    =   {   mailTo          = { initial = false }},
    
    execute = function(dz, item, info) 
       
        local function extractMailTo()
            rt = item.json
            dz.data.mailTo = rt.EmailTo
        end 
        
        local function getDomoticzSettings()
            local url         = dz.settings['Domoticz url'] .. "/json.htm?type=settings" 
            dz.openURL  ({ url = url, method = "GET", callback = httpResponse  })
        end    

        if item.isHTTPResponse then
            extractMailTo()
        elseif not dz.data.mailTo then
            getDomoticzSettings()
            return
        end
    
        -- Rest of script
        
        -- This one use the elegant method by taking the mailTo address from dz.data.mailTo
        dz.email(info.scriptName .. ". Triggered by event: " .. info.trigger ,"I got this Email adres from data", dz.data.mailTo )
        
        -- This one use the dirty method (using a dummy mailTo address, and produce an event eror but still ends up in your inbox 
        dz.email(info.scriptName .. ". Triggered by ëvent: " .. info.trigger ,"I use a dummy mailTo address","root@localhost")
        
        
    end        
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest