Mail Binding errors, but it used to work

I also checked the command line, JAF 1.2.0 is being added to the class path:

-classpath /usr/share/openhab/runtime/lib/boot/org.apache.karaf.diagnostic.boot-4.2.7.jar:/usr/share/openhab/runtime/lib/boot/org.apache.karaf.jaas.boot-4.2.7.jar:/usr/share/openhab/runtime/lib/boot/org.apache.karaf.main-4.2.7.jar:/usr/share/openhab/runtime/lib/boot/org.apache.karaf.specs.activator-4.2.7.jar:/usr/share/openhab/runtime/lib/boot/osgi.core-6.0.0.jar:/usr/share/openhab/runtime/lib/jdk9plus/istack-commons-runtime-3.0.8.jar:/usr/share/openhab/runtime/lib/jdk9plus/jakarta.xml.bind-api-2.3.2.jar:/usr/share/openhab/runtime/lib/jdk9plus/javax.activation-1.2.0.jar:/usr/share/openhab/runtime/lib/jdk9plus/javax.annotation-api-1.3.1.jar:/usr/share/openhab/runtime/lib/jdk9plus/jaxb-runtime-2.3.2.jar:/usr/share/openhab/runtime/lib/jdk9plus/txw2-2.3.2.jar

ls -Al /usr/share/openhab/runtime/lib/jdk9plus/javax.activation-1.2.0.jar
-rw-r--r-- 1 openhab openhab 78030 Apr 21 21:49 /usr/share/openhab/runtime/lib/jdk9plus/javax.activation-1.2.0.jar

I did a trial using thing and rules file.
For “application/javascript” the syntax might be different but that is out of my knowledge.

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.

Could you try to create a things file in /etc/openhab/things just compare against the setup that I have ?

Thing mail:smtp:mail [ hostname="smtp.XXXXX.com", sender="wolfgang.XXXXX@XXXXX.com", security="SSL", username="wolfgang.XXXXX@XXXXX.com", password="123456789" ]

and a rules file like:


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.

I’m using the 3.x UI and your logic doesn’t seem to work there.

I have:

triggers: []
conditions: []
actions: []

Nothing near what you posted.

This:

and:

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.

May I ask which mail provider you use ?

The suggested rule was in DSL, not javascript.

How do I define that?

“type: dsl” ?

I think you choose when clicking “add a script section” in the GUI

If you create a javascript rule you can test with the one line:

actions.get("mail", "mail:smtp:1032da1f").sendMail("youremail@gmail.com", "openHAB 3 front door bell", "Message" );

Change 1032da1f to what your smtp id is which is found in the things like below:

Run the rule from the bottom left hand corner:
image

That is what I already have, it is something in the call to sendMail.

Something is getting broken when upgrading from 2.x to 3.x and I have no idea where to look.

I didn’t change any of the SMTP server settings, server name, encryption, user and password are all unchanged.

I’ll try adding the “dsl” script

There is more going wrong than I think.
Trying to access the log via the browser brings this!

I can only find references to that file in the “*.bak” files.

Did this:


and I don’t see it being activated in the log.

What is that screenshot of? Did you save that in some file, in some folder?

If you don’t know how to use DSL, stick with your javascript. Find out how to make a log entry from javascript, see if that javascript rule triggers.

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

And Wolfgang_S asked me to run is in that form.

Please don’t get all high and mighty when I’m trying my damnedest to deliver the information requested. Jeez

In scripts as I was informed by YOURSELF where I should put it: