Email not sending (gmail)

would like to send an email with openhab2 (Raspberry). Unfortunately it does not work. Always get the following error message:

2017-12-07 19:43:44.462 [ERROR] [internal.handler.ScriptActionHandler] - Script execution failed: ReferenceError: “sendmail” is not defined in at line number 1

The file mail.cfg I have configured according to the instructions.
The rule was also configured.
Why is the script not running ???
Many Thanks.


You may need to post your config and rule to help trouble shoot. And I think you need to enable/install the mail action under addons in PaperUI.

This my mail.cfg

# the SMTP port to use (optional, defaults to 25 (resp. 587 for TLS/SSL))

# the username and password if the SMTP server requires authentication

# The email address to use for sending mails

# set to "true", if STARTTLS is enabled (not required) for the connection
# (optional, defaults to false)

And a rule

rule "Test Me"

	Time cron "0 0 20 * * ?"
	sendNotification("", "It is 8pm and you got an email.")


Thank you very much.
Unfortunately, email still does not work.
Can the cause be in Javascript?
Apparently you do not know Java’s commands?
The rule works.
The mail.cfg I have also checked, all right.


2017-12-07 20:56:36.084 [ERROR] [internal.handler.ScriptActionHandler] - Script execution failed: ReferenceError: “sendNotification” is not defined in at line number 1

I don’t know if this helps, but you have to go to your google mail settings and create a different login for the external application (openhab) if not done yet… because your default mail password will only work with gmail directly!
greets Dan


I have already done that too. I also tested another account. Even with this, the email function does not work.
Another idea?

Many Thanks.


do you use the above rule? there’s an error in it,

should be the username not the password… :wink:

1 Like


I checked the mail.cfg several times.
The error must be elsewhere.

Many Thanks.


There is possibly one other thing to check, and that is I think you need to change/allow a setting in your Google account settings to allow for 3rd party access.

Log int your account and visit Sign-in and Security. Then at the very bottom, make sure “Allow less secure Apps” is turned ON

Have you installed the Mail Action?


I did that first. After the installation but the mail.cfg is generated, which then needs to be adjusted.

Thank you.


Always gotta start with the basics. I can’t tell you how much time I’ve lost myself and helping others only to discover that the binding isn’t installed.

Just to be sure, double check that it shows as installed in PaperUI.

The reason why I’m focusing on this is that the error indicates that the sendMail Action doesn’t exist.


"Script execution failed: ReferenceError: “sendmail” is not defined in at line number 1

Should be sendMail. Case matters.

it’s alright I am thankful for every hint.
I have mail-action installed. Besides, I have openhab2 installed.
I feel that the script is not executed because it is not known.
I have been sitting over this problem for several days.
No matter which script write in the rule. It always comes the same error message.
Can not execute script.
Does the email service work for you without problems? Have also been several times the mail action installed or uninstalled. Without success.
The mail.cfg was also checked or adjusted several times.
I am desperate, where is my mistake.

Many Thanks.


Wait, you are trying to call the sendMail action from a JavaScript script in the new Experimental Rules Engine? I’m not sure you can call Actions from the Experimental Rules Engine and I’m positive you cannot from JavaScript like that, of it there is a way I don’t know it and it is not documented yet.

There is a reason why it has “Experimental” in the name.


I already suspected that. Yes, I use Rule Experimental.
Can I initiate email delivery in another way?
I have no experience there. Where do you embed such a script?
Many Thanks.


Start with


and come back if something doesn’t make sense.

Well, it is clearly labeled “Experimental” and states in the docs:

Note: If you use it, this is at your own risk. Especially, you should not expect any documentation besides what is available on the Eclipse SmartHome website.

I don’t consider it a bug when it has been clearly labeled as experimental and the first line in the documentation is a warning that this is a work in progress, not yet complete, and it has no documentation yet.

The Beginner’s Tutorial does not reference the Experimental Rules Engine and the old text-based Rules DSL and even JSR223 Rules are given higher prominence in the docs.

I’m not sure what else we could do but am open to suggestions.

I know he is based on the screenshot and the fact that he has access to writing rules in JavaScript.

Personally, if I were a new user I would stay away from anything labeled “Experimental” with the warning that there is no docs for it yet. But many new users are either not seeing those warnings or ignoring them.

And that is why the Experimental Rules Engine was created as a complete replacement for the Rules DSL. It needs to be relatively easy for non-programmers to use, have a web based way to develop rules, support Rule reuse (i.e. reusable libraries, not copy and paste from examples), support “real” programming languages as well as support for something like Scratch. All of these are goals of the Experimental Rules Engine, but it is under development and not ready for general use yet.

But ultimately, I think something like NodeRed is a more realistic analog than IFTTT which, in my opinion, provides too simple of a set of features to handle some of the surprisingly complex use cases users seem to come up with. For example, unless something has changed recently, I can’t loop, I can’t perform complex conditional logic, and I can’t interact with more than one input and/or output channel on a single applet.

Thank you for your information.
The email dispatch finally works for me.
As you have already mentioned, email delivery at Rule (Experimental) does not work !!!
That’s an important insight for me.
Since I do not know the syntax, I have created a rule with the graphical interface.
I copied the commands and entered the command (Sendmail …) by hand.
After several attempts finally worked. I am very happy because I have spent a lot of time on this problem.
That the rule (Experimental) does not work completely is completely normal. You just have to know !!!
But it will be of great help to people like me who do not know the syntax of a rule.
Thanks again for your help. Alone I could not have solved the problem !!!


@pinie_pinie, could you be so kind and show the code ?

Thank you,

As I said, I’m not the specialist.
My “rule” works with this code.
I switch a GPIO port (= Item: channel2) to “On”. Then an e-mail with the text “Test” should be sent.
Previously, I have adapted the file “mail.cfg” for my ID. This file can be found in the directory etc / openhab2 / services. In general, edit the files with the correct editor (for example, Ultra edit).
Then I created directory “etc / openhab2 / rules” the file “mail.rules”. I then copied the code into the file. If the item “channel2” switches to “ON” then the mail is sent.
I make no claim for the correctness of my description. Just try it, maybe you’re lucky.

// This rule file is autogenerated by HABmin.
// Any changes made manually to this file will be overwritten next time HABmin rules are saved.

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

// Global Variables

rule “mail"
Item channel2 changed
if ((channel2.state == ON)) {
sendMail("”, “Test”, “This is the message.”)

As you can see, I copied the contents of the rule from the “Habmin” / “Rule”.