[solved] E-Mail notification not working

Raspberry Pi v.3+
Openhab 2.4

I read almost all post related to not working e-mail notification. Most of them are related to problems with gmail. In my case I want to contact to another provider. E-mails sent with another devise are working properly so I am sure there is no problem with server, account or passwd. settings
Kindly ask to check if I do something wrong.

  • E-Mail notification shall be sent via switch. I installed Add On Mail Action from Paper UI.
  • Created a item switch in my UI
Switch  Send_via_Mail_Switch        "Send via Mail"     <switch>
  • Created rule:
rule "Send Notification via Mail"
when
    Item Send_via_Mail_Switch changed
then
    if(Send_via_Mail_Switch.state == ON)
    {
        logInfo("notifications", "Sending notification via mail.")
        sendMail("my@mail.com", "Mail Notification", 
        "This is our notification sent via mail.")

        Send_via_Mail_Switch.postUpdate(OFF)
    }
end
  • Configured the mail.cfg
hostname=smtp.domain.com
# the SMTP port to use (optional, defaults to 25 (resp. 587 for TLS/SSL))
port=465

# the username and password if the SMTP server requires authentication
username=username@domain.com
password=mypasswd

# The email address to use for sending mails
from=mymail@domain.com

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

Independently how I play with account settings I always get connection failed failue:

2019-05-18 17:22:19.833 [INFO ] [smarthome.model.script.notifications] - Sending notification via mail.
2019-05-18 17:22:19.937 [ERROR] [rg.openhab.action.mail.internal.Mail] - Could not send e-mail to 'my@mail.com'.

org.apache.commons.mail.EmailException: javax.mail.MessagingException: Connect failed;

  nested exception is:

	java.net.ConnectException: Connection refused (Connection refused)
	at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1393) ~[?:?]
	at org.apache.commons.mail.Email.send(Email.java:1447) ~[?:?]
	at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:157) ~[?:?]
	at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:89) ~[?:?]
	at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:67) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1086) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1061) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1047) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:992) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:151) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:902) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:865) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:224) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:204) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:447) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:228) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:204) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:460) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:244) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:204) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:447) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:228) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:204) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:190) ~[?:?]
	at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:82) ~[?:?]
	at org.eclipse.smarthome.model.rule.runtime.internal.engine.RuleEngineImpl.lambda$2(RuleEngineImpl.java:341) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

Caused by: javax.mail.MessagingException: Connect failed
	at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:210) ~[27:javax.mail:1.4.4]
	at javax.mail.Service.connect(Service.java:295) ~[27:javax.mail:1.4.4]
	at javax.mail.Service.connect(Service.java:176) ~[27:javax.mail:1.4.4]
	at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1388) ~[?:?]
	... 40 more

Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:?]
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:?]
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:?]
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:?]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:?]
	at java.net.Socket.connect(Socket.java:589) ~[?:?]
	at java.net.Socket.connect(Socket.java:538) ~[?:?]
	at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288) ~[27:javax.mail:1.4.4]
	at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231) ~[27:javax.mail:1.4.4]
	at com.sun.mail.pop3.Protocol.<init>(Protocol.java:107) ~[27:javax.mail:1.4.4]
	at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:261) ~[27:javax.mail:1.4.4]
	at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:206) ~[27:javax.mail:1.4.4]
	at javax.mail.Service.connect(Service.java:295) ~[27:javax.mail:1.4.4]
	at javax.mail.Service.connect(Service.java:176) ~[27:javax.mail:1.4.4]
	at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1388) ~[?:?]
	... 40 more

Is my switch notification setup proper?
How can I test if connection to smtp server works?
Appreciate your feedback.

Could be a firewall issue. Can you access the mail account from another mail app on the openHAB box?

Also check to see if your mail provider has disabled TLS 1.0. If they did, the v1 mail action will not work (although with my provider they throw an authentication error).

try to telnet to the smtp server on port 465 from openhab and see if that works

I do not think so. I am able to access my e-mail account from other apps within my home network without problems.
I checked also sending mail from standard smtp port: 25. I do not have any complicated routers in my network.
Raspberry Pi is originally installed with openHabian, without any modifications.
Slowly I am running out of ideas.

But can you access the email account from a mail app running on the openHAB box?

If so, since you’ve enabled TLS in the mail action config, did you check to see if your email provider has disabled TLS 1.0?

Mark,
I am quite new to openHab - kindly ask for understanding if I come with not logic answers. I am not aware about any mail app on the openHab (Paper UI - bindings, things, configuration, items etc.) I have only Mail Action Add-on installed:

On the myopenhab.org I have admin account with the same mail as I want to send messages from my openhabian server. This mail and account works OK.

I checked account setting at my provider, and there are no blocking points and no information about missing support on tls. Settings i shall use for smtp configuration:

otgoing mail server - smtp.wp.pl
ort - 465
ecurity - SSL
Server requires authentication / SMTP authorization ON

I checekd with ssl and/or tls activated. In both cases received problems. I also checked on standard ports without encryption - the same failure.
If you could guide me step by step I might get logs and slowly come to solution. If there is any mail app on openhab, please let me know how to activate it. Maybe this is the point I am missing

br
JD

Thank you Christos for the hint. I want to avoid installing any additional programs on my Pi. telnet/sendmail or similar is not installed with openhabian image. But… if I there will be no progress on solving I have to follow your instructions.

BR
JD

No worries. I’m trying to narrow things down so we can identify the cause of the problem.

Correct. I understand that.

If you can access your email successfully from other hosts, but not the openHAB host, then it must be something about the host running openHAB, or the openHAB app itself.

I was hoping you could run another mail application on the openHAB host just to test that you can access your mail account from the openHAB host using another mail app. It doesn’t matter which mail app. That would narrow the problem down to something related to openHAB. If possible, can you temporarily install a mail app on that host and test that you can or cannot access your email account?

Could you possibly email their support to ask if they disallow TLS 1.0? That would be the quickest way to eliminate that as a possible cause of the problem.

If you google for “tls 1.0 email disabled” you will see that there are scores of posts about TLS 1.0 being disabled. PCI (Payment Card Industry) has a way of getting providers to sunset old (and no longer secure) protocols.

My email provider finally got around to disabling it a couple weeks ago (which broke the openHAB mail action). That’s why it’s top of mind for me. :wink:

The last thing I would suggest is that you enable DEBUG mode on the mail action. In the console, just type this, then invoke your rule that sends email. Perhaps there will be something in the log that gives us a clue.

log:set DEBUG org.openhab.action.mail

Dear Jacek

so if these are the settings you should use to connect to your mail.
Try the following: telnet smtp.wp.pl 465
on your openhab box
if everything is fine the connection should open. i.e blank line waiting for your input.
If there is an issue the session would not open and you should receive an error.
It would mean that probably a firewall is blocking it.

this test is one of the most simple and common in IT to check if a connection to specific network service is working.

Cheers
Stefan

1 Like

Dear all,
thank you very much for your comments and support. I was playing with telnet (that worked) and different settings. At the end I came up with system reboot. Surprisingly this resolved my problems. Initial settings of my e-mail account were correct. Probably due to changing them all the time the system was lost.
Thanks for the support again.

Hello! My openhab 2.5.2 has the error. Please tell me how can I solve this problem?
My openhab log viewer:
“[INFO ] [inding.mail.internal.POP3IMAPHandler] - error when trying to refresh IMAP: Connection dropped by server?”
Help me please…