markistodd101988 / openhab

Automatically exported from code.google.com/p/openhab
0 stars 0 forks source link

SMTP does not seem to work with Gmail #304

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Configure openhab.cfg to use SMTP:

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

2. Create a rule in demos.rule to send a test mail:

rule "E-mail"
when
    System started 
then    
    sendMail("youruser@gmail.com","Test e-mail","Test e-mail") 
end

3. Launch OpenHAB

What is the expected output? 

To get an e-mail

What do you see instead?

The rule is launched, but the mail fails to send.
I get a message saying "Send failure"

What version of the product are you using? On what operating system?

OpenHAB 1.2.0
Windows 7

Please provide any additional information below.

I tried all possible combinations of ports 25, 587 and 465, with and without 
TLS. The failure message changes but it nevers sends the e-mail.

I doubled checked user and password.

I tried different gmail accounts with the same results.

I even tried with hotmail (smtp.live.com), with the same results...

I tried two different PCs with Windows 7.

I just don't know what else to try.
Please help.

Thanks in advance

Original issue reported on code.google.com by serca...@gmail.com on 16 May 2013 at 8:35

GoogleCodeExporter commented 8 years ago
Title should be "SMTP does not seem to work with Gmail" instead of "SMPT does 
not seem to work with Gmail". My apologies...

Original comment by serca...@gmail.com on 16 May 2013 at 8:37

GoogleCodeExporter commented 8 years ago
changed title

Original comment by teichsta on 17 May 2013 at 5:07

GoogleCodeExporter commented 8 years ago
My guess is that is something related with Apache.

The code in 'openhab.io.net.actions.Mail.java'  seems OK.

I tried with a local server without authentication (port 25) and it did not 
work.
If I make a telnet (port 25) to this server, I am able to send the e-mail 
manually (by writing the commands in the console), so it seems to be a problem 
with 'org.apache.commons.mail.SimpleEmail' class.

In fact the exception is thrown at line 132 of 
'openhab.io.net.actions.Mail.java', where the SimpleMail.send() method is 
invoked.

I use Java 1.7.0_21-b11.

Any thoughts?

Original comment by serca...@gmail.com on 17 May 2013 at 4:48

GoogleCodeExporter commented 8 years ago
It works for me with the same configuration

Original comment by esch...@gmail.com on 20 May 2013 at 1:22

GoogleCodeExporter commented 8 years ago
I think it may be related with Apache configuration or with some kind of 
environment variable, but I have no clue at all of which one...
I am almost sure is not a problem of the server.

Did this happen to anyone else?

Original comment by serca...@gmail.com on 20 May 2013 at 1:32

GoogleCodeExporter commented 8 years ago
I am also successfully using the mail action since a long time (but not with 
gmail) and have no problems whatsoever with it...
Do you see any more information in the log than "Send failure", if you start in 
debug mode?

Original comment by kai.openhab on 20 May 2013 at 7:12

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I also have gmail functional with the config above - BUT, I'm using Linux.

Original comment by hlw31...@gmail.com on 30 May 2013 at 9:32

GoogleCodeExporter commented 8 years ago
This is the result I get, in debug mode, when using

mail:hostname=smtp.gmail.com
mail:port=465
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=true

15:49:26.963 DEBUG o.o.m.r.i.engine.RuleEngine[:277] - Executing startup rule 
'SMTP'
>>>>>Sending data EHLO Heimdall<<<<<<
>>>>>Sending data QUIT<<<<<<
15:49:27.232 ERROR o.openhab.io.net.actions.Mail[:136] - Could not send e-mail 
to 'sercasyr@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:1242)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by: javax.mail.MessagingException: java.net.SocketException: Software 
caused connection abort: socket write error
        at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.sendLine(SMTPTransport.java:1702)
        at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.sendQuit(SMTPTransport.java:1459)
        at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.close(SMTPTransport.java:732)
        at javax.mail.Transport.send(Transport.java:144)
        at javax.mail.Transport.send(Transport.java:48)
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
15:49:27.235 INFO  o.o.m.c.i.f.FolderObserver[:163] - Loaded file 'demo.rules'

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

the result is:

15:52:48.450 DEBUG o.o.m.r.i.engine.RuleEngine[:277] - Executing startup rule 
'SMTP'
>>>>>Sending data EHLO Heimdall<<<<<<
>>>>>Sending data QUIT<<<<<<
15:52:48.707 ERROR o.openhab.io.net.actions.Mail[:136] - Could not send e-mail 
to 'sercasyr@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:1242)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by: javax.mail.SendFailedException: Send failure 
(javax.mail.MessagingException: Server doesn't support required transport level 
secu
rity)
        at javax.mail.Transport.send(Transport.java:163)
        at javax.mail.Transport.send(Transport.java:48)
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729)
Caused by: javax.mail.MessagingException: Server doesn't support required 
transport level security
        at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.sendHandshake(SMTPTransport.java:1840)
        at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:393)
        at javax.mail.Service.connect(Service.java:265)
        at javax.mail.Service.connect(Service.java:85)
        at javax.mail.Service.connect(Service.java:70)
        at javax.mail.Transport.send(Transport.java:94)
        at javax.mail.Transport.send(Transport.java:48)
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
15:52:48.711 INFO  o.o.m.c.i.f.FolderObserver[:163] - Loaded file 'demo.rules'

And with:

mail:hostname=smtp.gmail.com
mail:port=25
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=false

the result is:

15:55:13.565 DEBUG o.o.m.r.i.engine.RuleEngine[:277] - Executing startup rule 
'SMTP'
>>>>>Sending data EHLO Heimdall<<<<<<
>>>>>Sending data AUTH LOGIN<<<<<<
>>>>>Sending data c2VyY2FzeXI=<<<<<<
>>>>>Sending data c2N5ODA1MXljcw==<<<<<<
>>>>>Sending data QUIT<<<<<<
15:55:13.839 ERROR o.openhab.io.net.actions.Mail[:136] - Could not send e-mail 
to 'sercasyr@gmail.comæ.
org.apache.commons.mail.EmailException: Sending the email to the following 
server failed : smtp.gmail.com:25
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by: javax.mail.SendFailedException: Send failure 
(javax.mail.AuthenticationFailedException: Error authenticating with server)
        at javax.mail.Transport.send(Transport.java:163)
        at javax.mail.Transport.send(Transport.java:48)
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729)
Caused by: javax.mail.AuthenticationFailedException: Error authenticating with 
server
        at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:402)
        at javax.mail.Service.connect(Service.java:265)
        at javax.mail.Service.connect(Service.java:85)
        at javax.mail.Service.connect(Service.java:70)
        at javax.mail.Transport.send(Transport.java:94)
        at javax.mail.Transport.send(Transport.java:48)
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:132)
        at org.openhab.io.net.actions.Mail.sendMail(Mail.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:55:13.843 INFO  o.o.m.c.i.f.FolderObserver[:163] - Loaded file 'demo.rules'

Original comment by serca...@gmail.com on 30 May 2013 at 1:57

GoogleCodeExporter commented 8 years ago
What about
mail:popbeforesmtp=true

Original comment by hlw31...@gmail.com on 30 May 2013 at 3:44

GoogleCodeExporter commented 8 years ago
I tried that also, but it does not work...

This is what I get with

mail:hostname=smtp.gmail.com
mail:port=587
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=true
mail:popbeforesmtp=true

17:51:32.328 ERROR o.openhab.io.net.actions.Mail[:136] - Could not send e-mail 
to 'sercasyr@gmail.comæ.
org.apache.commons.mail.EmailException: Connection failed 
(java.lang.IllegalArgumentException: port out of range:-1)
        at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1203)
Caused by: javax.mail.MessagingException: Connection failed 
(java.lang.IllegalArgumentException: port out of range:-1)
        at org.apache.geronimo.javamail.store.pop3.POP3Store.protocolConnect(POP3Store.java:141)
Caused by: java.lang.IllegalArgumentException: port out of range:-1
        at java.net.InetSocketAddress.checkPort(Unknown Source)
17:51:32.330 INFO  o.o.m.c.i.f.FolderObserver[:163] - Loaded file 'demo.rules'

This is what I get with

mail:hostname=smtp.gmail.com
mail:port=465
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=true
mail:popbeforesmtp=true

17:53:34.637 ERROR o.openhab.io.net.actions.Mail[:136] - Could not send e-mail 
to 'sercasyr@gmail.comæ.
org.apache.commons.mail.EmailException: Connection failed 
(java.lang.IllegalArgumentException: port out of range:-1)
        at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1203)
Caused by: javax.mail.MessagingException: Connection failed 
(java.lang.IllegalArgumentException: port out of range:-1)
        at org.apache.geronimo.javamail.store.pop3.POP3Store.protocolConnect(POP3Store.java:141)
Caused by: java.lang.IllegalArgumentException: port out of range:-1
        at java.net.InetSocketAddress.checkPort(Unknown Source)

Original comment by serca...@gmail.com on 30 May 2013 at 3:56

GoogleCodeExporter commented 8 years ago
does the problem still occur?

Original comment by teichsta on 12 Jul 2013 at 3:18

GoogleCodeExporter commented 8 years ago
Yes, indeed.
I did not find a solution... nor an explanation that answers why it does not 
work for me.

Original comment by serca...@gmail.com on 12 Jul 2013 at 3:37

GoogleCodeExporter commented 8 years ago
i managed to send email from my MacOS system with to following properties:

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

Can you confirm that they work for you as well? 
(http://stackoverflow.com/questions/848794/sending-email-in-java-using-apache-co
mmons-email-libs gave a hint).

Regards,

Thomas E.-E.

Original comment by teichsta on 13 Jul 2013 at 8:38

GoogleCodeExporter commented 8 years ago
any news?

Original comment by teichsta on 13 Aug 2013 at 4:11

GoogleCodeExporter commented 8 years ago
No,

I've just lost all hope in getting it working...

Original comment by serca...@gmail.com on 16 Aug 2013 at 2:17

GoogleCodeExporter commented 8 years ago
Anyone has succesfully sent an e-mail using OpenHAB in Windows 7?

Original comment by serca...@gmail.com on 28 Sep 2013 at 9:04

GoogleCodeExporter commented 8 years ago
I am starting to think that the problem is the OS...

Original comment by serca...@gmail.com on 28 Sep 2013 at 9:07

GoogleCodeExporter commented 8 years ago
As we are doing nothing particular, but simply using Apache commons-email, you 
might want to check on the web if there are any known issues regarding this 
library on Windows 7.

Original comment by kai.openhab on 29 Sep 2013 at 3:44

GoogleCodeExporter commented 8 years ago
I hope this can help.
Just tested this on Win8, this works for me.

OS: 
Win 8 64bit
JDK:
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

OpenHAB 1.4.0-SNAPSHOT:
commit 29ab2f10c977c38a77571e055ddc58bc5d79260d
Merge: 345fed9 1737950
Author: kaikreuzer <kai@openhab.org>
Date:   Sat Oct 5 20:23:05 2013 -0700

    Merge pull request #27 from kgoderis/tcppatch

    Fix sequence of Quartz startup in configureBinding()

Original comment by yuri.cau...@gmail.com on 7 Oct 2013 at 2:44

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I had one glitch afterwards (probably lost my connection for a minute), but it 
keeps on working now.

Original comment by yuri.cau...@gmail.com on 7 Oct 2013 at 7:38

GoogleCodeExporter commented 8 years ago
Am I supposed to set up or reinstall Apache, or is this something that OpenHAB 
does?
I agree that it looks like a problem with Apache but I have no clue at all...
Maybe it is not a problem with Windows 7 but something I am missing to do with 
Apache.

Original comment by serca...@gmail.com on 8 Oct 2013 at 7:07

GoogleCodeExporter commented 8 years ago
Hi,

Have you tried using another gmail account?

Here are my findings to the other configs you posted:

When I try to send email using:
mail:hostname=smtp.gmail.com
mail:port=25
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=false

I get an error Connection timed out.
So it does need tls to be true. I like this, it's secure!

Using:
mail:hostname=smtp.gmail.com
mail:port=465
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=true
mail:popbeforesmtp=true

Gives me a port out of range error, I don't like pop so I would set that to 
false...
Anyway 465 is for smtps... config looks awkward.

When trying with:
mail:hostname=smtp.gmail.com
mail:port=465
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=true

This takes too long to wait for the time-out ;-)
I suppose because we try to connect on port 465 on an smpt (not smtps) server.
Read this: 
http://stackoverflow.com/questions/15796530/what-is-the-difference-between-ports
-465-and-587

Google does not have smtps.google.com

So the only working configuration for me is:
mail:hostname=smtp.gmail.com
mail:port=587
mail:username=myuser
mail:password=mypassword
mail:from=myuser@gmail.com
mail:tls=true

Did you download the openhab-runtime.zip, unpack that and run start.bat?

The error you get: Server doesn't support required transport level secu
rity, makes me think you have something configured in your gmail that blocks 
the connection...

I have another gmail account with two-factor auth, using this account I get :
10:09:38.627 ERROR o.o.action.mail.internal.Mail[:142] - Could not send e-mail 
to 'yuri.cauwerts@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:1242)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:138)
    at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:82)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729)
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713)
    at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)
Caused by: javax.mail.SendFailedException: Send failure 
(javax.mail.AuthenticationFailedException: Error authenticating with server)
    at javax.mail.Transport.send(Transport.java:163)
    at javax.mail.Transport.send(Transport.java:48)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:138)
    at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:82)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729)
Caused by: javax.mail.AuthenticationFailedException: Error authenticating with 
server
    at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:402)
    at javax.mail.Service.connect(Service.java:265)
    at javax.mail.Service.connect(Service.java:85)
    at javax.mail.Service.connect(Service.java:70)
    at javax.mail.Transport.send(Transport.java:94)
    at javax.mail.Transport.send(Transport.java:48)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:138)
    at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:82)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Try using a 'clean' gmail account...

Original comment by yuri.cau...@gmail.com on 8 Oct 2013 at 8:11

GoogleCodeExporter commented 8 years ago

Original comment by teichsta on 5 Nov 2013 at 10:47

GoogleCodeExporter commented 8 years ago
This issue has been migrated to Github. If this issue id is greater than103 its 
id has been preserved on Github. You can open your issue by calling the URL 
https://github.com/openhab/openhab/issues/<issueid>. Issues with ids less or 
equal 103 new ids were created.

Original comment by teichsta on 17 Nov 2013 at 8:08

GoogleCodeExporter commented 8 years ago
see above!

Issue has been migrated to Github and should be discussed there.

Original comment by teichsta on 21 Nov 2013 at 1:51