Email not sending (gmail)

296/5000
Hello,
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.

Thoralf

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

hostname=smtp.gmail.com

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

# the username and password if the SMTP server requires authentication
username=myusername@gmail.com
password=mypassword

# The email address to use for sending mails
from=mypassword@gmail.com

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

And a rule

rule "Test Me"

when
	Time cron "0 0 20 * * ?"
then
	sendNotification("myusername@XXXX.com", "It is 8pm and you got an email.")
end

Hallo,
249/5000
Hello,

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.

Thoralf

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

Hello,

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

Many Thanks.

Thoralf

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

should be the username not the password… :wink:

1 Like

Hello,

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

Many Thanks.

Thoralf

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?

Hello,

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

Thank you.

Thoralf

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.

Wait…

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

Should be sendMail. Case matters.

650/5000
Hello,
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.

Thoralf

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.

Hello,

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.

Thoralf

Start with

http://docs.openhab.org/tutorials/beginner/rules.html

then

http://docs.openhab.org/configuration/rules-dsl.html

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.

Hello,
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 !!!

Thoralf

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

Thank you,
Dominik

Hello,
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.

mail.rules:
// 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"
when
Item channel2 changed
then
if ((channel2.state == ON)) {
sendMail("xxx@x.de”, “Test”, “This is the message.”)
}
end

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

Thoralf