Mail Action 2.5 fails with exception

I’m trying to get mail action to to work in a rule. I get the following error:

[WARN ] [ab.binding.mail.internal.SMTPHandler] - Trying to send mail but exception occured: Sending the email to the following server failed : gamubaru.com:587

I don’t know how to get more details about the exception.

I tried the python sending script using the same credentials:

Sending from the rule, on the mail server side it complains: SSL3 alert read:fatal:certificate unknown.

I tried removing the mail binding, clearing the cache and re-installing the binding.

My mail.things is:

Thing mail:smtp:gamubarusmtp [ hostname="gamubaru.com", sender="zzzz@gamuaru.com", popbeforesmtp="false", security="TLS", port=587, username="zzzzz@gamubaru.com", password="xxxx" ]

The rule is doing:

rule "Dryer State"
when
	Item dryerControl changed
then
     val mailActions = getActions("mail","mail:smtp:gamubarusmtp")
     if(dryerControl.state == 0) {
	logInfo("Dryer control", "Off")
	mailActions.sendMail("zzzz@gamuaru.com", "Dryer state", "The dryer control is off.")
	}
     if(dryerControl.state == 1) {
	logInfo("Dryer control", "On")
	mailActions.sendMail("zzzz@gamuaru.com", "Dryer state", "The dryer control is on.")
	}
end

I also tried creating a mail.cfg file. I think that is for the 1.x binding however.

I’m running openhab 2.5 on a raspberry pi 4.

Thanks

Hi Andy,
did you configure the mail.cfg?
here is mine:

# The SMTP server hostname, e.g. "smtp.gmail.com"
hostname=smtp.gmail.com

# the SMTP port to use (optional, defaults to 25 (resp. 587 for TLS/SSL))
port=587

# the username and password if the SMTP server requires authentication
username=myuser@gmail.com
password=mypassword

# The email address to use for sending mails
from=openHAB.PIN@gmail.com

# set to "true", if STARTTLS is enabled (not required) for the connection
# (optional, defaults to false)
tls=true

# set to "true", if SSL negotiation should occur on connection
# do not use both tls=true and ssl=true
# (optional, defaults to false)
# ssl=true

# set to "true", if POP before SMTP (another authentication mechanism)
# should be enabled. Username and Password are taken from the above
# configuration (optional, default to false)
popbeforesmtp=false

# Character set used to encode message body
# (optional, if not provided platform default is used)
#charset=

This worked without any problems.
regards
Georg

The OP is using Mail Action 2.5 not the 1.x version.

How can I install Mail Action 2.5? I am running 2.5 stable release but in PaperUI in the Add-ons Actions list I can only find the 1.x version. Did you succeed to install it?

Yes, I configured the mail.cfg and use the Mail Action (1x).

Everything works fine – no need to change.

Georg

You can install the 2.5.0 jar file in usr/share/addons then restart OH.
https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.binding.mail/

Thank you for that hint. Is there any special reason why the Mail Action is only delivered via addons-file?

No, I’m really sure why it’s not available via PaperUI.

It’s a bug and should show up as legacy. I started to fix this last time it came up in the forum, but stopped myself since it was a waste of time… 1.x compatibility has been removed in OH 3.0.

I definitely have Mail 2.5:

openhab> bundle:list|grep -i mail
308 │ Active │  80 │ 1.6.2                   │ JavaMail API
309 │ Active │  80 │ 2.5.0                   │ openHAB Add-ons :: Bundles :: Mail Binding

Is there anything I can do to turn on more logging?

Set logging to DEBUG or TRACE via the console.

Mail 2.5 is no longer an Action. You can find it in the Bindings section now. Accessing the action is a little different too. Look in the Binding’s docs to see examples for how. It is available but it’s in a different category.

Over time, I expect the Actions category to completely go away. The OH 2.x way of managing Actions is through Bindings, not as a separate Action add-on.

I tried setting debug logging based on the exception that I had:

log:set DEBUG ab.binding.mail

That does not give me any more information. All I see is:
[WARN ] [ab.binding.mail.internal.SMTPHandler] - Trying to send mail but exception occured: Sending the email to the following server failed

Is the ab.binding… something outside openhab?

Maybe should be org.openhab.binding.mail but not sure as I do not have this binding installed. If you use bundle:list in console it should show everything you have.

rikoshak,

patterned my rule off the sample in the binding docs.

val mailActions = getActions("mail","mail:smtp:gamubarusmtp")
mailActions.sendMail("zzzz@gamuaru.com", "Dryer state", "The dryer control is off.")

It looks like I’m doing that part correctly. I’m guessing that there is a problem with my Thing configuration. That seems pretty straight forward however. Not sure how I could mess it up :slight_smile:

Assuming the binding is installed correctly, which seems to be the case, there might be something wrong with the Thing. We need to see what that exception is because it could also be a temporary network issue or something like that too.

If it’s not printing the exception in the logs, we need to put the mail binding into debug or trace level logging. The easiest would be to log into the karaf console and issue the command

log:set DEBUG org.openhab.binding.mail

That will put the mail binding and just the mail binding into DEBUG log level. Everything else remains unchanged.

Check if you also have the v1 action installed (actions= line in addons.cfg)

Enable mail logging as Rich said. Eventually you are not allowed to relay mails ? I recently stumbled across that. Double-check sender address.

Thank you very much for clarification, Rich!