Page 1 of 1

how to send email from python plugin?

Posted: Tuesday 06 January 2026 20:13
by willemd
Does the Python plugin framework have any command for sending a notification by email, similar to the DzVents "domoticz.notify" command ?

I want to send an email from a python plugin when a critical error occurs that requires attention.

I could create a JSON call with the "sendnotification" parameter, but am wondering whether there is a more elegant method.

Re: how to send email from python plugin?

Posted: Tuesday 06 January 2026 21:58
by waltervl
I dont think that should be a feature of a plugin.

You can create and update an alert device with the plugin and have the user decide what he wants to do with the alert (to what notification system it needs to go etc).

Re: how to send email from python plugin?

Posted: Tuesday 06 January 2026 22:59
by willemd
Well, if the sole purpose of the plugin is to collect data and it determines that the communication is broken, why not send an alert ? I am making sure it only does it once, until the problem is solved and then reoccurs.

The route via a device is possible, maybe more flexible and less depending on presence of an email setup, but since I am maintaining the plugin I can just add that requirement to the documentation (or, maybe better, I can include a choice in the plugin startup config so the user can choose whether such alerts are desired or not).

In the meantime, I have tested the route via a JSON call and it works without problems.
/json.htm?type=command&param=sendnotification&subject=SUBJECT&body=THEBODY

Re: how to send email from python plugin?

Posted: Tuesday 06 January 2026 23:47
by waltervl
The plugin framework is designed to connect with external devices and update/command them, not to send notifications. Sending notifications is a function of Domoticz based on devices.
In the build-in hardware gateways there is also no option to send notifications from the hardware gateway.

Alternatively you can also put an Error message in the Domoticz log when this issue occurs and that (when configured) also sends an email notification.

When using Domoticz API calls in python plugins (there are more plugins that use that workaround) you also need to define the IP of the domoticz server in the plugin configuration as the plugin does not know it and can not query it.

Re: how to send email from python plugin?

Posted: Tuesday 06 January 2026 23:58
by FlyingDomotic
You also can send directly mail using Python library from plugin.

Re: how to send email from python plugin?

Posted: Wednesday 07 January 2026 9:26
by willemd
Thanks, I will use the Domoticz notification system. Below JSON call works fine.

Code: Select all

http://127.0.0.1:8080/json.htm?type=command&param=sendnotification&subject='ATTENTION: communication timeout'&body='Please check and restore the connection '