Hi all, first question second post. I recently installed openHAB 1.8.1 and have the demo working. I added my first rule. Turn off the kitchen ceiling light and it turns on the kitchen table light. I can see it works. I // the on command for the table light and add in
sendMail("xxx@gmail.com",“from openhab”,“Test1”)
and get nothing.
Log says
The name ‘sendMail(,,)’ cannot be resolved to an item or type.
I have downloaded an unzipped the addons in the addons folder in openhab.
org.openhab.action.mail-1.8.1.jar and org.openhab.binding.mailcontrol-1.8.1.jar are there, but I think I only need the first one. My config file looks like this:
######################## Mail Action configuration
mail:hostname=smtp.gmail.com
mail:port=587 mail:username=mymail@gmail.com
mail:password=mypass mail:from=mymail@gmail.com
mail:tls=true
This is hashed out: mail:popbeforesmtp=
This is hashed out mail:charset=
I am installed on a raspberry pi 2B.
I had success with msmtp sending mail from command line so used the same ports and info from there. I am sending a certificate with msmtp though and not openHAB. Anyone have any idea whats wrong?
If you want to make sure that “email” is working… Add something like this to the beginning of you rule file and it should email you whenever the rule file is loaded.
rule “On System Startup"
when
System started
then
sendMail("tmymail@gmail.com”, “This is the email subject”, “This is the email body”)
end
Not sure what to make of this…I did what Tommy suggested. I pasted the rule and changed to my email. I restarted the openhab service and didn’t get any indication the rule failed. Nothing in the event log and no email. I turned the light on and off and generated the error. Went to gmail for my openhab send account and nothing there. Was I supposed to rebot the pi?
rule “On System Startup"
when
System started
then
sendMail("xxx@gmail.com”, “This is the email subject”, “This is the email body”)
end
rule “Light dependency”
when
Item Light_GF_Kitchen_Ceiling changed from ON to OFF
I would uncomment out the line for the kitchen table to help ensure the rule is firing off.
and perhaps recopy over the mail binding to ensure not a bad ftp transfer, etc. And although yours sendMail looks correct, below is also what I use that includes the date and time in the email body.
sendMail("xxxxx@xxxx.com", "Light Turned On", "The Family Room Light was turned on at " + Date.state.format("%tr") +" on "+ Date.state.format("%tD"))
I also just remembered something, and not sure if it is needed or not.
But in your gmail account, go to your account settings | sign in & security. And at the bottom turn on the “Allow Less Secure Apps”
OK, if I put the rule turning the kitchen table light on after the sendmail it doesn’t work, but if I flip it and put the rule about the kitchen table light before the sendmail, it works. I rebooted the pi this time.
Less secure apps is on from when I made msmtp work about a month ago. Didn’t know if it was needed either, but I eliminated it at that time.
Is the sendmail the same one as the sendmail I would use from PHP or the command line? If so I could try a debug method of sending from the command line.
Can I command line execute from a rule like I can in PHP with and echo or something?
Here is another thought…I changed the folder permissions so I can use SAMBA. Could that be causing the mail.jar to fail?
I remembered some interesting information. I had trouble with ssmtp on my pi. I ended up trying msmtp. That worked. The difference being msmtp had certificates. I downloaded a bundle and added a line. This is my msmtp config:
account default
host smtp.gmail.com
port 587
from mymail@gmail.com
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on
user mymail@gmail.com
password Mypass
logfile ~/.msmtp.log
The line i added to my openhab config is
mail:tls_trust_file /etc/ssl/certs/ca-certificates.crt
Does anyone know if there is a way to see the hanshake like dumping to a logfile like they did in the bugfix or like my msmtp config? I would the be able to verify its the cert.