I copied your code and tried it on my system and it worked after I removed the “!” and changed the email address and the smtp id to my settings
Here is my test code:
triggers:
- id: "4"
label: an item state is updated
description: This triggers the rule if an item state is updated (even if it does
not change).
configuration:
itemName: FrontDoor
state: OPEN
type: core.ItemStateUpdateTrigger
conditions: []
actions:
- inputs: {}
id: "3"
label: execute sendMail
description: Use script to send mail
configuration:
type: application/javascript
script: >-
mailActions = actions.get("mail","mail:smtp:d7887864")
mailActions.sendMail("test@gmail.com", "Front door opened", "Front door was opened");
type: script.ScriptAction
Change the email to address to your email address and see what happens.
If you still get the error then we can discount a coding issue and it will be something else.
I put your smtp id back again in the above example.
If it fails then maybe remove the mail binding and reinstall it.
Hi Greg, I didn’t see that you had added to the thread so sorry for the late reply.
I already tried it without the “!” and it is still broken.
My system is an upgrade from an existing “2.x” installation (something that the OP also did) and I am beginning to suspect that something goes wrong or is missing following the provided instructions.
I’ll reinstall the extension as I don’t fancy reflashing the Pi as there are other services on it like zigbee2mqtt.
Removing and installing the binding had no effect. It is still showing the same error in the log.
It has to be something to do with the upgrade, could there be something left over from the 2.x installation that is breaking something? I did as the migration said and also “uninstalled” version 2.
rule "mail message"
when Time cron "0/59 * * * * ?" //run every 59 seconds
then
logInfo("mail rule", "send a mail via mail binding")
val mailActions = getActions("mail","mail:smtp:mail")
val success = mailActions.sendMail("wolfgang.XXXXX@XXXXX.com", "Test from openhab", "This is the mail content.")
//logInfo("mail rule", success)
end
Of course you need to replace the related items with your stuff.
Hopefully this is the same (I have my variables in the javascript):
triggers:
- id: "1"
configuration:
cronExpression: 0/59 * * * * ?
type: timer.GenericCronTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >-
logInfo("mail rule", "send a mail via mail binding")
mailActions = getActions("mail","mail:smtp:mail")
mailActions.sendMail("wolfgang.XXXXX@XXXXX.com", "Test from openhab", "This is the mail content.")
type: script.ScriptAction
Not working because of logInfo: 2021-06-14 22:57:02.243 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'cee58d381e' failed: ReferenceError: "logInfo" is not defined in <eval> at line number 1
And removing that line now causes: 2021-06-14 23:00:01.459 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'cee58d381e' failed: ReferenceError: "getActions" is not defined in <eval> at line number 1
So your test doesn’t work at all, if anything it is worse, not even getting to the Java-Mail API.
Adding “actions.getActions” as here: mailActions = actions.getActions("mail","mail:smtp:d7887864");
doesn’t work either:
2021-06-14 23:10:01.319 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘cee58d381e’ failed: TypeError: actions.getActions is not a function in <eval> at line number 1
Sorry, as I have not used the UI to setup any rule yet the background of my idea was if you could use a things file that is to be stored in a file in /etc/openhab/things directory and a rule like a cron entry which is to be stored in a file in /etc/openhab/rules directory. The syntax does not work in the UI as you use it and it also does not cover the functionality you would like to implement that is correct. I just was looking for a do a test that is exactly comparable.
If the rule didn’t trigger then there wouldn’t be the error, right?
2021-06-10 12:29:09.533 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtpserver:465
2021-06-10 12:29:09.611 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8