Can't get sendMail to work in OH2

Is there someone sending mail through gmail smtp in OH2?

I’m using the same settings I did in OH1
hostname=smtp.gmail.com
port=587
username=******
password=******
tls=true

I’ve double and triple checked the username and password.
I’ve removed all import org.openhab… from the *.rules file.

Anyone with an idea (or that can decrypt the error message)?
I get the following error message
2016-12-17 14:04:56.996 [ERROR] [rg.openhab.action.mail.internal.Mail] - Could not send e-mail to ‘myemail@gmail.com’.
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
at org.apache.commons.mail.Email.send(Email.java:1448)
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)[:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_111]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1085)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1060)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1046)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:991)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:114)[127:org.eclipse.smarthome.model.script:0.9.0.201612091054]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:459)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:243)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:77)[128:org.eclipse.smarthome.model.script.runtime:0.9.0.201612091054]
at org.eclipse.smarthome.model.script.engine.ScriptExecutionThread.run(ScriptExecutionThread.java:42)[127:org.eclipse.smarthome.model.script:0.9.0.201612091054]
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.SocketTimeoutException: connect timed out
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
… 29 more
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)[:1.8.0_111]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)[:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)[:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)[:1.8.0_111]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.8.0_111]
at java.net.Socket.connect(Socket.java:589)[:1.8.0_111]
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:286)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
… 36 more

This points to a problem with your Network setup. Did you verfiy that you can send a mail with another computer on your own network?

Also, https://support.google.com/a/answer/176600?hl=de points out that you need TLS for port 587. I am not sure whether we have this capacity as I am sending mails always to my own servers which trust hosts on the “internal” network :smile:

These settings work for me:

mail:hostname=smtp.gmail.com
mail:port=587
mail:username=you@gmail.com
mail:password=yourpassword
mail:from=you@gmail.com
mail:tls=true

@hakan is right that something in your network setup is likely preventing your outbound connection on port 587 to smtp.gmail.com.

I had an odd problem, although a different error message: in OH1.8 my setting was:

mail:from=first.last

and that worked fine

but in OH2.0 it refused to work until I changed it to first.last@gmail.com

Dan

I’m running exactly the same setup parameters as I did with OH1 (identical to watou’s except that the mail.cfg file doesn’t include the ‘mail:’ part).
The OH1 have successfully been sending at least one mail per day for the past two years so there is no problems having anything going out on port 587 from the router. Don’t know if there could be something blocking openhab from accessing the port internally on the odroid. No idea what that would be though. It’s a fresh install of the ubuntu 16.04 minimalistic image and I’ve added nothing that should block the port as far as I know.

I’ve tried different accounts and also different service suppliers without result. Also tried SSH instead of TLS but that changes nothing.

Something is definitely up with openHAB though. After playing around I’m back to my OH1 setup with
hostname=smtp.gmail.com
port=587
username=******
password=******
tls=true

But even after I power cycled the unit the port is listed as 465 in the ERROR output.
Neither 465 nor SSH can be found in the jsondb. I deleted everything from my mail.cfg file (except the five lines above) just to be certain there isn’t anything fish going on there.

Where can this information be stored?!?! Where is openHAB digging up the port number from. Now I’m really lost!!

2016-12-19 20:54:32.705 [ERROR] [rg.openhab.action.mail.internal.Mail] - Could not send e-mail to ‘myemail@gmail.com’.
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
at org.apache.commons.mail.Email.send(Email.java:1448)
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)[:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_111]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1085)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1060)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1046)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:991)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:114)[127:org.eclipse.smarthome.model.script:0.9.0.201612171108]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:459)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:243)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189)[143:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:77)[128:org.eclipse.smarthome.model.script.runtime:0.9.0.201612171108]
at org.eclipse.smarthome.model.script.engine.ScriptExecutionThread.run(ScriptExecutionThread.java:42)[127:org.eclipse.smarthome.model.script:0.9.0.201612171108]
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.SocketTimeoutException: connect timed out
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
… 29 more
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)[:1.8.0_111]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)[:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)[:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)[:1.8.0_111]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.8.0_111]
at java.net.Socket.connect(Socket.java:589)[:1.8.0_111]
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)[:1.8.0_111]
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:286)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:205)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
… 36 more