notififications / alerts/ emails on change in sensor value

HI MIchal,

i tried the instructions at this link you suggested below but i am getting errors- i am wondering if it has to do with the OR 2.6 beta with new drools version or Java version 8

https://openremote.github.io/archive-dotorg/forums/22872974.html

below is the copy of the rule and the error messages- i hope its something simple :slight_smile: Any help is greatly appreciated.

I have 2 drl files in the rules folder - one with working set of rules and other with the rule for email for testing.

//trial email with orcbeta2.6

package org.openremote.controller.model.event

global org.openremote.controller.statuscache.CommandFacade execute;

global org.openremote.controller.statuscache.SwitchFacade switches;

global org.openremote.controller.statuscache.LevelFacade levels;

import org.openremote.controller.protocol.Event;

import java.util.Properties;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

// email notifications

rule “Send mail”

when

Switch ( source == “Send mail sensor”, value == “on”)

then

execute.command (“Send mail OFF”);

final String username = “orc@gmail.com”;

final String password = “mypassword”;

Properties props = new Properties();

props.put(“mail.smtp.host”, “smtp.gmail.com”);

props.put(“mail.smtp.socketFactory.port”, “465”);

props.put(“mail.smtp.socketFactory.class”,“javax.net.ssl.SSLSocketFactory”);

props.put(“mail.smtp.auth”, “true”);

props.put(“mail.smtp.port”, “465”);

Session session = Session.getInstance(props,

new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username, password);

}

});

try {

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress(“orc@gmail.com”));

message.setRecipients(Message.RecipientType.TO,

InternetAddress.parse(“orc@gmail.com”));

message.setSubject(“trial”);

message.setText(“triall triall”);

Transport.send(message);

System.out.println(“Mail sent”);

} catch (MessagingException e) {

throw new RuntimeException(e);

}

end

ERROR messages:

DEBUG 2017-03-12 22:16:12,460 : Starting event processor: Drools Rule Engine

DEBUG 2017-03-12 22:16:12,583 : Adding Rule ‘trial_modeler_rules.drl’…

DEBUG 2017-03-12 22:16:12,584 : Adding Rule ‘modeler_rules.drl’…

INFO 2017-03-12 22:16:21,149 : Starting device discovery service…

DEBUG 2017-03-12 22:16:21,150 : checking for discovered devices…

ERROR 2017-03-12 22:16:22,581 : Rule definition ‘trial_modeler_rules.drl’ could not be deployed. See errors below.

ERROR 2017-03-12 22:16:22,584 : Rule Compilation error Only a type can be imported. javax.mail.PasswordAuthentication resolves to a package

Only a type can be imported. javax.mail.internet.InternetAddress resolves to a package

Only a type can be imported. javax.mail.Message resolves to a package

Only a type can be imported. javax.mail.Transport resolves to a package

Only a type can be imported. javax.mail.MessagingException resolves to a package

Only a type can be imported. javax.mail.Session resolves to a package

Only a type can be imported. javax.mail.internet.MimeMessage resolves to a package

Session cannot be resolved to a type

Session cannot be resolved

javax.mail.Authenticator cannot be resolved to a type

Message cannot be resolved to a type

MimeMessage cannot be resolved to a type

InternetAddress cannot be resolved to a type

Message.RecipientType.TO cannot be resolved to a type

InternetAddress cannot be resolved

Transport cannot be resolved

MessagingException cannot be resolved to a type

ERROR 2017-03-12 22:16:22,586 : Error importing : ‘javax.mail.PasswordAuthentication’

ERROR 2017-03-12 22:16:22,586 : Error importing : ‘javax.mail.internet.MimeMessage’

ERROR 2017-03-12 22:16:22,587 : Error importing : ‘javax.mail.MessagingException’

ERROR 2017-03-12 22:16:22,588 : Error importing : ‘javax.mail.internet.InternetAddress’

ERROR 2017-03-12 22:16:22,588 : Error importing : ‘javax.mail.Session’

ERROR 2017-03-12 22:16:22,589 : Error importing : ‘javax.mail.Transport’

ERROR 2017-03-12 22:16:22,590 : Error importing : ‘javax.mail.Message’

INFO 2017-03-12 22:16:24,056 : Added rule definition ‘modeler_rules.drl’ to knowledge.

INFO 2017-03-12 22:16:33,971 : Started event processor : Drools Rule Engine