Configuring a Mail Rule in OH3

I have the binding installed and the settings in there. I assume I need to run some script instead of just making a selection. I guess there is no mail item to select. Can someone share a simple script with me to just send a single email? I tried searching but the documentation is a bit over my head.

I don’t know if this is the best or recommended way, but after creating the SMTP Server thing I then used the below in a rule (created in the UI) in the Then clause and “execute a given script” action:

sendMail(getActions("mail","mail:smtp:XXXXXXX"), "me@example.com", "My Subject", "My mail body.")

Replace mail:smtp:XXXXXXX with whatever ID is given to the SMTP Server thing.

KFStein, thanks. Couldn’t get that to work but I found this which did: How to send mails in OH3? - #11 by rlkoshak

The short version is that I chose Rule DSL for the scripting language & then used this:

val mailActions = getActions(“mail”,“mail:smtp:XXXXXXXX”) mailActions.sendHtmlMail(“me@myemail.com”, “Email Subject”, “Email Body”)

This line can NOT be a global variable which is disappointing because I had to add it in 330 places in my rules ;-(

Best, Jay

The good news is, it works better that way.
It’s very host timing dependent, but people loading an Action like Mail at the head of a rules often complain of the Action being null at rule execution time. Loading Action when required gives the binding time to initialise the Action fully, which could be dependent on external services.

1 Like