sendMail not working

I am no longer able to send email from rules (I used to before I did a reinstall of openHAB about a month ago). The error I get is:

2020-05-20 11:17:56.739 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘notification test’: The name ‘mailActions’ cannot be resolved to an item or type; line 7, column 1, length 11

I have the MailBinding installed, and I set up both a cfg file and a thing.

mail.cfg

hostname=smtp.gmail.com
port=587
username=myemail@gmail.com
password=mypassword
from=myemail@gmail.com
tls=true
ssl=false

mail.things

Thing mail:smtp:testmail [ hostname=“smtp.gmail.com”, sender="myemail@gmail.com", security=“TLS”, port=587, username="myemail@gmail.com", password=“mypassword” ]

And this is the rule

rule “notification test”
when
Item jack changed
then
val mailActions = getActions(“mail”,“mail:smtp:samplesmtp”)
if (jack.state == ON) {
logInfo(“notifications”, “Sending notification via app.”)
mailActions.sendMail(“myemail@gmail.com”, “Test”,
“This is our notification sent via app.”)
sendNotification(“myemail@gmail.com”,
“This is our notification sent via app.”)

jack.postUpdate(OFF)
}
end

sendNotification works by itself but sendMail doesn’t work.

I’ve read through similar messages on the forum but can’t get this to work.

Mike

your val declaration has to be moved out of the rule to the top.

When I moved it to the top of the file I got the following error:

Rule ‘notification test’: Instance is not of class SendMailActions.

Please compare your thing definition withe the val declaration.
smtp:testmail versus smtp:samplesmtp
It has to be the same.

Thanks, I think I’m almost there! Now I’m getting a STARTTLS command first error. I’m guessing that’s a setting in the things file but I can’t figure it out.

Change from TLS to STARTTLS in your thing definition.

This discussion thread worked for me. Thanks for the help!

for anyone, looking why sendMail action suddenly stops working:

  • restarting openHAB resolved this issue for me.

It seems, that this is a “valid” workaround at the moment, as openHAB is plagued with a problem in regards to actions: