Using ArrayList with JavaScript in OH3 to send mail with attachment using sendHtmlMail

  • Platform information:
    • Hardware: Raspberry Pi 4
    • OS: Raspbian
    • openHAB version: 3.0.1

I’m trying to call the sendHtmlMail method from a smtp-thing, while adding an attachment as ArrayList in JavaScript.
I had done this previously successfully in OH 2.5 using the default rule-languge, so following example works perfectly in OH 2.5:

val List<String> attachmentUrlList = newArrayList("file:///C:/openhab/conf/html/carport/ipcamera.gif")
val mailActions = getActions("mail","mail:smtp:16158a15")
mailActions.sendHtmlMail("", "subject", "body", attachmentUrlList)

I’m currently in a process of moving to OH 3.0.1 and would prefer using JavaScript for all my scripts/rules, which I’m way more familiar in, but for some reason I can’t get that array list working and always end up with the a log message explaining me that the fourth parameter does not exist in the method signature:

var mailActions = actions.get("mail","mail:smtp:5041fc7916");
mailActions.sendHtmlMail("", "subject", "body", ["/tmp/test"]);
2021-03-24 10:56:54.006 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'c2e0c762c4' failed: TypeError: Can not invoke method [jdk.dynalink.beans.SimpleDynamicMethod Boolean org.openhab.binding.mail.internal.action.SendMailActions.sendHtmlMail(String,String,String)] with the passed arguments; they do not match any of its method signatures. in <eval> at line number 11

As soon as I leave out the fourth parameter the mail is successfully send, but I obviously want to have that attachment in the mail as well.

Bear in mind the Action expects a Java List type object. I expect it chokes on a different javascript object type. I don’t have a cure to offer, but you must somehow create a java.util.List I think.
β€œstream” might be a clue word here? (or is that going the other direction?!)

Thanks that helped me already in understanding way more of the internals how to create Java types in JavaScript, but even an ArrayList or ListString didn’t change the log-output.

var arrayListType = Java.type("java.util.ArrayList")
var arrayList = new arrayListType();
var listType = Java.type("java.util.List")
var list = new listType(new String("/tmp/test"));

may be this helps, it seems as if the function names changed …
JavaScript cannot attach file to email