Cannot specify to: address in Email Sender Notification

I’m attempting to set up email notifications in the Rule engine but I’m having some troubles.

When I view my Email Sender thing options, I can generate a new test email by clicking on Send Email and it works as expected.

But when I add an Email Sender Notification in the Rule builder, I only see options for Title, Message and Level, no To. The Rule works, but it just sends the email to the address that the email is configured with (the To and From fields are the same.

Is this by design? Am I missing something?

Yes, this is by design. Notifier add-ons only ever take those 3 inputs, so we had to use the configured to: address as a workaround. To properly support this, the rules system needs to support actions with inputs as rule effects, which is something I haven’t yet had time to tackle.

I also wanted to be able to send emails with arbitrary content and more importantly to an arbitrary address.

My motivation for this is to be able to send from my ISP email address to my cellular providers email to text gateway – so that I can get a text on, for example, motion detected. (I am more likely to check a text than an email)

So I adapted the Python webthing to do this.

(https://github.com/mozilla-iot/webthing-python/tree/master)

I suppose the ideal thing to do this would be a notifier – but there wasn’t a convenient Python example for the notifier as there was for a webthing. I wanted to use Python because I prefer the language and because of its SMTP library. No doubt there is some equivalent for javascript.

The example shows invoking the thing by running the python script at the command line:
$ python3 single-thing.py

This works nicely (I am able to send emails to arbtrary addresses with arbitray subject/content), however it’s not viable for autostarting (don’t want to have to go to the command line every time the gateway restarts and then retype the above command)

My question is two fold 1. how to run -any_ general user code at gateway startup. I thought I had come across some details on that very subject earlier but now I cant find it.

Is it possible to post a start up sequence diagram similar to the one at:


I’m looking for a hook to get the webthing running.
  1. Alternatively how do you add the thing to the addons directory (or should you?) in such a way that it is found and started by the gateway framework?

Some more detail on the mail sender:

Essentially its just derived from the lamp webthing example – wherein the onoff property is removed but a bunch of string (and one integer) properties are added to configure the sender.

The rules engine can set these properties based on another property (e.g. motion detected, door sensor activated and so on) I didn’t have a useful sensor so for development/experimentation I switched mine based on the on/off property of another light.

In the rules engine when the light turns on it sets the email sender’s properties (e.g. to address) and also activates the send action – in other words I have a single thing on the left and two instances of the same thing (my email sender) on the right – the first instance of the sender is used to set the to address property (additional instances could set message text etc).

The last instance of the sender sets the send action which starts an SMTP email client and sends the mail as configured.

The send action occurs after the property is set which is critical (otherwise email address, content etc wont be correct). I’m not sure if this order is always the case (i.e. events after properties) or is a function of the order in which I added the outputs/responses to the rules page.

I initially coded this up to work with the ON property – that works but, an action is obviously the preferred approach. One thing I discovered when using the property is that the “handler” function (the lambda function in the value member of the property is called before the actual property is set. (The passed in new property value is correct – but a get property will return the old value -only after the lambda completes will the webthing show the new property value).

I changed the type of the thing from an “OnOffSwitch” too a”Sender” – which isn’t in the schema- but it does show up as a label when you search for the new thing – although not on the things page – its still just identified as a generic “THING” - just like the available email sender.

I’ll post the code here or github if there’s in any interest in this approach.

Thanks,

Adding to my own post here - for now (i.e. absent any gateway hook/knowledge thereof) - I am trying to start the thing server using systemd but, not having luck with that either - again starting at the command line works - just cant get it to autostart:

[Unit]
Description=Start the EmailSender Web Thing (EmailSender.py)
After=multi-user.target

[Service]
ExecStart=/usr/bin/python3 /home/pi/EmailSender.py

[Install]
WantedBy=multi-user.target

Adding yet again to my own thread - figured out the service start issue - running a Pyhon script to start the webthing - but service starts as root user - and Python modules not installed for root user - so generates a module import error.
using journalctl was invaluable in finding this.

The fix is to run the service as the pi user (which has the modules installed). To do this add this line in the service file file under the service section:
User=pi:

So the service file is:
[Unit]
Description=Start the EmailSender Web Thing (EmailSender.py)
After=multi-user.target

[Service]
User=pi
ExecStart=/usr/bin/python3 /home/pi/EmailSender.py

[Install]
WantedBy=multi-user.target

Your design is awesome and you can send emails with arbitrary content to an arbitrary address if only you have done a good javaScript email validation

But you also need to debug your Python code very well after checking everything