Configuring email connections

New User here — I have OPENHAB running on my RPi 4 and generally the functionality is behaving. However, I have been unable to get email connections to behave. I have added the binding, added SMTP Server item, but try as I may, I am unable to successfully connect email.

I have a light that is configured and operational (for on/off). I have attempted to add a rule to send a notification when the status changes from On to Off (also tried the other way). The logs indicate the rule has triggered, but I get this message:
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘c7156a0a16’ failed: var notifications = ___ Java.type(‘org.openhab.io.openhabcloud.NotificationAction’);

The thing shows a status of online.

This is the rule that raises the aforementioned error.:

configuration: {}
triggers:
** - id: “1”**
** configuration:**
** command: ON**
** itemName: FloorLight**
** type: core.ItemCommandTrigger**
conditions: []
actions:
** - inputs: {}**
** id: “3”**
** configuration:**
** type: application/vnd.openhab.dsl.rule**
** script: >**
** var notifications =**
** Java.type(‘org.openhab.io.openhabcloud.NotificationAction’);**

** notifications.sendNotification(‘adena@moretrees.world’,‘This is a test’);**
** type: script.ScriptAction**

I am sure that I have something misconfigured, but I haven’t found a good set of (beginner) instructions to properly configure it and/or properly trigger it. Any advise is greatly appreciated.

sendNotification is not sending a SMTP email. It is about pushing a notification via the app.
To send an email you need to use one of these actions: Mail - Bindings | openHAB that are made available via the mail binding.

I have my mail binding set up, but see no way to trigger it.


UID: mail:smtp:0d5ea03e0a
label: SMTP Server
thingTypeUID: mail:smtp
configuration:
hostname: moretrees.world
password: xxxxx
security: STARTTLS
port: “587”
sender: admin@moretrees.world
username: admin
location: Universal

Clearly, I am off track. I created the SMTP binding, it shows online, but no channels.
I am now trying to call it, but whenever I find examples to mimic, none of them work. If somebody can get me started, I am sure i can figure out where I have gone sideways.

The email server is on the same box (it is a citadel server). The email does work, I have tested SMTP. I can send email from other computers using the smtp configuration.

I did set up several items (again, found samples online). These make no sense to me at this point…so I do not know if they are correct or another red herring.

I tried several methods of scripts/rules but none of them behave. Blockly offers a “send email notification”, I have also tried JS.

Spinning my wheels at this point…

This works for me. I trigger the DSL rule when an a server goes offline.

var String statusString = "Offline, not seen in over 10 minutes"
val eventTime = triggeringItem.lastUpdate("mapdb") 

val mailActions = getActions("mail","mail:smtp:7edd26b383")

mailActions.sendMail("XXXXXXX", triggeringItem.name, triggeringItem.name + statusString + eventTime.toString )
mailActions.sendMail("YYYYYYY", triggeringItem.name, triggeringItem.name + statusString + eventTime.toString )

logInfo("Device offline rule","Messsage sent")

vMailActionsEnabled.sendCommand(OFF)

Mail thing code:

UID: mail:smtp:6555a781b4
label: Mail - SMTP Server
thingTypeUID: mail:smtp
configuration:
  hostname: smtp.gmail.com
  password: WWWWWWWWWWW
  security: SSL
  sender: nYYYYY@YYY.us
  username: XXXXXXX@gmail.com

THANK YOU! Not there yet but progress…

Current Error:
2022-01-23 16:00:09.864 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘c7156a0a16’ failed: :1:11 Expected ; but found statusString
var String statusString = “Light turned on”
^ in at line number 1 at column number 11

Code:
var String statusString = “Light turned on”
val eventTime = triggeringItem.lastUpdate(“Floor Light”)

val mailActions = getActions(“mail”,“mail:smtp:0d5ea03e0a”)

mailActions.sendMail(“adena@moretrees.world”, triggeringItem.name, triggeringItem.name + statusString + eventTime.toString )
mailActions.sendMail(“adena@moretrees.world”, triggeringItem.name, triggeringItem.name + statusString + eventTime.toString )

logInfo(“Device offline rule”,“Messsage sent”)

vMailActionsEnabled.sendCommand(OFF)

Something must be wrong with my syntax…

Progress!
I am now getting this error message:
==> /var/log/openhab/openhab.log <==
2022-01-23 16:39:08.936 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : moretrees.world:587
2022-01-23 16:39:08.937 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: Could not convert socket to TLS;

I am confused because I have my SMTP Server set for STARTTLS, compared the settings to an SMTP connection that is working and found no difference. Please advise…

Do you have an SMTP server such as: ssmtp installed on your Raspberry Pi? This link is for ssmtp which I have used for a while. Apparently it is no longer maintained but the link shows other options. It will do the forwarding to your email server.

I do not have a SSMTP server, but I do have a SMTP server installed (and operational). If I use SSMTP, do I need to create another THING for it, or how do I point at this alternate method?

When I linked Thunderbird mail client and hooked it to my RPi email server, I did need to add a certificate exception (or something to that effect) before it would connect. Could I be running into the same thing…and if so, how would I go about addressing it?

Thanks so much for all the assistance.

Use port 25 and STARTTLS.