I am using Openhab 3 and have installed the mail binding.
I can send emails successfully without attachments but cannot send with an attachment.
Here is what I have done that doesn’t work.
message = "Someone is at the front door at " + Date();
var attachmentUrlList = "file:///tmp/image.jpg" ;
actions.get("mail", "mail:smtp:1032da1f").sendHtmlMail("myemail@gmail.com", "openHAB 3 front door bell", message , attachmentUrlList);
This is the error I am seeing:
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘8e1e6893d6’ 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 at line number 96
I must be missing something obvious as sending email attachments should be something that is used everyday.
I have looked at the mail examples and they didn’t work.
Reading the link you referred to sounds like it can’t be done?
That is probably why I can’t find any information about attachments.
I would have thought this would have been an “out of the box” option.
Looks like I will have to do an exec to the server email command line.
It is “out of the box”, for the old style DSL rules as shown in the example.
You’ve chosen to write rules in javascript, which is at the moment a little less popular and well supported, so you get more of an “adventure” factor.
I would have expected the List creating method shown in the linked thread to have worked. Have you tried it?
That’s the extent of my javascript knowledge. You need someone else who’s figured out the knack here.
If you are desperate to make it work, you can used multiple rule languages at once. You can write a DSL rule just for this job.
I just wanted to use JavaScript only if I can. I know I can mix DSL.
I can run an exec eternal email if I have to but it would be nice if the JavaScript could do it.
I have made a bit of progress with trying to send multiple attachments but it fails.
var ArrayList = Java.type('java.util.ArrayList');
message = "<H2>Someone is at the front door at " + Date() + "</H2>";
attachmentUrlList = new ArrayList();
attachmentUrlList.add("http://192.168.0.164/zm/cgi-bin/zms?mode=single&monitor=6&scale=50");
attachmentUrlList.add("http://192.168.0.164/zm/cgi-bin/zms?mode=single&monitor=7&scale=50");
actions.get("mail", "mail:smtp:1032da1f").sendHtmlMailWithAttachment("myemail@gmail.com", "openHAB 3 front door bell", message , attachmentUrlList);
logger.info("The array list " + attachmentUrlList)
The log shows there are array items:
2021-04-20 10:15:52.836 [INFO ] [org.openhab.rule.8e1e6893d6 ] - The array list [http://192.168.0.164/zm/cgi-bin/zms?mode=single&monitor=6&scale=50, http://192.168.0.164/zm/cgi-bin/zms?mode=single&monitor=7&scale=50]
But the email doesn’t send because in the log it says:
2021-04-20 10:15:52.835 [WARN ] [mail.internal.action.SendMailActions] - Could not send mail: no protocol: [http://192.168.0.164/zm/cgi-bin/zms?mode=single&monitor=6&scale=50, http://192.168.0.164/zm/cgi-bin/zms?mode=single&monitor=7&scale=50]
I can send a single attachment and that works fine.
@naador That was exactly what I had but was missing the s for plural of attachments.
Thanks for the solution. I have spend weeks trying to get this to work.
That’s why copy and paste was invented…
I thought I was doing something wrong. My thoughts were surly this can’t be so hard and am I the only person trying to send multiple emails using JavaScript?
I have upgraded to OH 3.1.0.RC1 and now the email with attachments doesn’t work anymore.
It used to work on the stable release.
Here is the error I get.
2021-06-27 14:00:31.302 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘a118e0e70d’ failed: TypeError: null has no such function “sendHtmlMailWithAttachments” in at line number 329
I removed the old mail binding and installed the 3.1.0.RC1 binding but still doesn’t work.
EDIT: I have worked out what the issue is. The UUID had changed when upgraded.
It used to be this: mail:smtp:1032da1f but now it is this: mail:smtp:a514b96247
It works now.
I will have to go through my rules and find where else I use the send email.