Mail binding startup issues

Hi all,
I am on 2.5.5 stable on openHABian on a Pi3
I just moved from “mail action” to the new “mail binding”.
All setup is fine because the binding is not working only during startup. After the initial startup phase it works.

I get two different types of error:

  1. see 1st case: [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule ‘onStartup’: null
  2. see 2nd case: [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘ESP ANTIFURTO changed’: ‘sendMail’ is not a member of ‘org.eclipse.smarthome.core.thing.binding.ThingActions’

All my rules that run on System startup and have a sendMail are not executed.

=====Case 1=====
For example, this simple rule:
var systemStarted = new Boolean(false)

rule "onStartup" 
	System started
	val mailActions = getActions("mail","mail:smtp:myemail")

    	if(! systemStarted) {
        	systemStarted = true
		mailActions.sendMail("", "OH2 @ OH2 just STARTED", "OH2 just STARTED")
		sendNotification("", "INFO: OH2 just started")

generates the following error in the log file:

2020-05-28 12:27:01.340 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'onStartup.rules'
2020-05-28 12:27:18.780 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'onStartup': null

=====Case 2=====
This rule is triggered during the startup phase (when the Item is updated by mqtt), see that it is triggered few seconds after the previous error:

rule "ESP ANTIFURTO changed"
	Member of gESPAntifurto changed
	val mailActions = getActions("mail","mail:smtp:myemail")

	mailActions.sendMail("", "Antifurto changed", "Antifurto changed")
	sendNotification("", "Antifurto changed")

generates this error:

2020-05-28 12:27:53.726 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'ESP ANTIFURTO changed': 'sendMail' is not a member of 'org.eclipse.smarthome.core.thing.binding.ThingActions'; line 155, column 2, length 77
2020-05-28 12:27:53.737 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'ESP ANTIFURTO changed': 'sendMail' is not a member of 'org.eclipse.smarthome.core.thing.binding.ThingActions'; line 155, column 2, length 77

Can anyone help?

Sometimes Rules will be loaded and parsed and start running before the rest of the openHAB configs have been loaded and started. If they work a little while after startup this is almost certainly the cause of the problem.

If you are using openHABian, there is an option in openhabian-config to address this problem.

thanks for your reply Rich.
What is the option in openHABian to address this problem?

To be honest I wanted to migrate from mqtt v1 to mqtt v2 binding, but the fact to have the risk to have rules that start before the bindings are loaded is quite risky, as the whole rule is not executed…

This has been a problem with openHAB since version 2.0 and it is completely independent of MQTT, either version of the binding.

40 openHAB related -> 44 Delay rules load

NOTE: this is only a problem with Rules DSL. When using Scripted Automation the Rules don’t start running until well after everything else has completed loading.

Hi Rich.

openHABian delay rules option seems to have fixed it! Thanks for the tip.
I wonder why this option only available in openHABian and not in the other distros…

It’s not a problem for everyone. It’s frankly a hack to work around a bug. It can cause problems of it’s own for some users (which is why it’s optional to begin with). It’s not relevant to all distros and/or other distros work differently so the solution would need a different implementation. There is no such thing as openhabian-config on other distros.