[SOLVED] Mail action - connect failed

mail
sendmail
Tags: #<Tag:0x00007f1e68ffa6d0> #<Tag:0x00007f1e68ffa400>
(Georg Jungermann) #1

I try to setup mail communication - but it Fails to connect to the mail server.

here my mail.cfg

# 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=myuser@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=true

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

my sendMail rule

rule "Test Mail"
when 
   Item Reload_Variables changed
then
   sendMail("myuser@gmail.com", "This is the email subject", "This is the email body")
end

after the rule is triggered - I get following event log

2018-01-11 16:47:03.569 [ERROR] [rg.openhab.action.mail.internal.Mail] - Could not send e-mail to 'myuser@gmail.com'.
org.apache.commons.mail.EmailException: javax.mail.MessagingException: Connect failed;
	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) ~[?:?]
Caused by: javax.mail.MessagingException: Connect failed
	at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:210) ~[30:javax.mail:1.4.5]
	at javax.mail.Service.connect(Service.java:295) ~[30:javax.mail:1.4.5]
	at javax.mail.Service.connect(Service.java:176) ~[30:javax.mail:1.4.5]
	at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1388) ~[?:?]
	at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319) ~[30:javax.mail:1.4.5]
	at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233) ~[30:javax.mail:1.4.5]
	at com.sun.mail.pop3.Protocol.<init>(Protocol.java:111) ~[30:javax.mail:1.4.5]
	at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:261) ~[30:javax.mail:1.4.5]
	at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:206) ~[30:javax.mail:1.4.5]
	at javax.mail.Service.connect(Service.java:295) ~[30:javax.mail:1.4.5]
	at javax.mail.Service.connect(Service.java:176) ~[30:javax.mail:1.4.5]
	at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1388) ~[?:?]

Using a different user - there are the same error Messages.
An der Karaf console erhalte ich folgendes log

19:30:07.890 [ERROR] [org.openhab.action.mail.internal.Mail] - Could not send e-mail to 'myuser@gmail.com'.
org.apache.commons.mail.EmailException: javax.mail.MessagingException: Connect failed;
  nested exception is:
        java.net.ConnectException: Die Wartezeit f▒r die Verbindung ist abgelaufen (Connection timed out)
        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.GeneratedMethodAccessor73.invoke(Unknown Source) ~[?:?]
        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:1085) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1060) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1046) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:991) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:141) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:215) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:215) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189) ~[?:?]
        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:343) ~[?:?]
        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) ~[30:javax.mail:1.4.5]
        at javax.mail.Service.connect(Service.java:295) ~[30:javax.mail:1.4.5]
        at javax.mail.Service.connect(Service.java:176) ~[30:javax.mail:1.4.5]
        at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1388) ~[?:?]
        ... 31 more
Caused by: java.net.ConnectException: Die Wartezeit f▒r die Verbindung ist abgelaufen (Connection timed out)
        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:319) ~[30:javax.mail:1.4.5]
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233) ~[30:javax.mail:1.4.5]
        at com.sun.mail.pop3.Protocol.<init>(Protocol.java:111) ~[30:javax.mail:1.4.5]
        at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:261) ~[30:javax.mail:1.4.5]
        at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:206) ~[30:javax.mail:1.4.5]
        at javax.mail.Service.connect(Service.java:295) ~[30:javax.mail:1.4.5]
        at javax.mail.Service.connect(Service.java:176) ~[30:javax.mail:1.4.5]
        at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1388) ~[?:?]
        ... 31 more

But I can send mails with the same Information direct from python

#! /usr/bin/python

import smtplib
from email.mime.text import MIMEText

SERVER =    'smtp.gmail.com'
PORT =      587
EMAIL =    'myuser@gmail.com'
PASSWORT =  'mypassword'
EMPFAENGER =    ['myuser@gmail.com' ]
SUBJECT =   'Testmail'
BODY =      """
<html>
 <head></head>
  <body>

<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-0ord{text-align:right}
.tg .tg-qnmb{font-weight:bold;font-size:16px;text-align:center}
</style>
<table class="tg">
  <tr>
    <th class="tg-qnmb" colspan="2">Testmail!!!!</th>
  </tr>
</table>
  </body>
</html>
"""

session = smtplib.SMTP(SERVER, PORT)
session.set_debuglevel(1)
session.ehlo()
session.starttls()
session.ehlo
session.login(EMAIL, PASSWORT)
msg = MIMEText(BODY, 'html')
msg['Subject'] = SUBJECT
msg['From'] = EMAIL
msg['To'] = ", ".join(EMPFAENGER)
session.sendmail(EMAIL, EMPFAENGER, msg.as_string())
session.quit()

I have checked all mail related Messages - but didn’t find any similiar reason.

Thanks for your Support

0 Likes

(Martin Korsrud) #2

This is kind of a long shot, but I notice that you have commented out the ssl support in the cfg file. Could that make it difficult to send email on port 587?

0 Likes

(Georg Jungermann) #3

Thank your comment, Martin!
Unfortunately I forgot to mention that I have tested all 5 variations:

#SSL = true
#TLS = true
#popbeforesmtp=true
#port = 25
#port=

the result was always the same - connect failed.
Kind regards
Georg

0 Likes

(darkcheater) #4

Since you are using Google Mail, I remember that you have to accept the external connection from a “less secure client” like the OpenHAB email action in the Google Mail settings.
I might however be wrong since I never used the OpenHAB email action.
Check this: https://support.google.com/accounts/answer/6010255

0 Likes

(Georg Jungermann) #5

Hi!

I found the error which ist indicated in following message Using GMAIL to send mail with the Mail Action 1.9.0.b5.
The Parameter popbeforesmtp is on default true and not false - setting popbeforesmtp=false solved the problem.
my mail.cfg looks now:

# 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=myuser@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=

Thanks for helping

0 Likes

(Jems Smith) #6

Mail connection contains the connection and login information for your email server. you can simply configure your email account. you can also use the Roadrunner Email.if your Roadrunner Email not working then please contact Roadrunner Signup for the best solution.

0 Likes

(Mark Ford) #7

I hardly ever write comments on blogs, but your article urged me to praise your blog. For instant support related to the Email please visit Email Customer Service for the solution.

0 Likes