[SOLVED] Help with mail action gmail error Could not send e-mail

Tags: #<Tag:0x00007f5c94921538> #<Tag:0x00007f5c949213f8>

Hi everyone i’m trying to setup the mail action addon receiving error

23:10:20.504 [ERROR] [rg.openhab.action.mail.internal.Mail] - Could not send e-mail to 'sXXXXX4@live.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.GeneratedMethodAccessor88.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_161]
        at java.lang.reflect.Method.invoke(Unknown Source)[:1.8.0_161]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1085)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1060)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1046)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:991)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:114)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:77)[130:org.eclipse.smarthome.model.script.runtime:0.9.0.b5]
        at org.eclipse.smarthome.model.script.engine.ScriptExecutionThread.run(ScriptExecutionThread.java:42)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1880)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:648)
        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)
        ... 22 more
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.ssl.Alerts.getSSLException(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.Handshaker.fatalSE(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.Handshaker.fatalSE(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.Handshaker.processLoop(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.Handshaker.process_record(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)[:1.8.0_161]
        at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
        at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:447)
        at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1875)
        ... 29 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.validator.PKIXValidator.doBuild(Unknown Source)[:1.8.0_161]
        at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)[:1.8.0_161]
        at sun.security.validator.Validator.validate(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)[:1.8.0_161]
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)[:1.8.0_161]
        ... 40 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)[:1.8.0_161]
        at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)[:1.8.0_161]
        at java.security.cert.CertPathBuilder.build(Unknown Source)[:1.8.0_161]
        ... 46 more

chopped the rest off will post if needed

i have installed the binding/addon and filled in the mail.cfg with details found in other post and my own details

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
mail:username=sXxxxxx1@gmail.com
mail:password=XXXXXXXXXXX

# The email address to use for sending mails
from=sXxxxxx1@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=

# 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

My message rule

rule "rule name"
when
    Item Test_Rule_Trigger changed from OFF to ON
then
    sendMail ("sXXXXX4@live.com", "Test", "This is the message.")
end

Any recommendations welcome

Google uses nonstandard ports. Use port 465.

Also, if you have 2 factor authentication you need to generate an application password to use here or Google will never permit the login.

im not having much luck with this one rich i have tried the differnet port numbers i have also changed settings in the mail.cfg as posted by other people i have also enabled logins from less secure apps still receive the same error

two factor is turned off i just checked

@Sharpy i just set it up on my rpi and got it working immediately.

You got some text “mail:” before your username and password? Remove it and try it again!

Here is my setting, i also changed it to tsl and it worked albeit i am not 100% sure if it changed the setting as there was nothing logged.

#https://support.google.com/a/answer/176600?hl=de

# The SMTP server hostname, e.g. "smtp.gmail.com"
hostname=smtp.gmail.com
#No dynaminc IP 
#hostname=smtp-relay.gmail.com

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


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

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

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

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

# Character set used to encode message body
# (optional, if not provided platform default is used)
#charset=
rule "test"
  when
    Item Test_1 changed 
 then
   logInfo("Test Mail", "Sending Mail" )
   sendMail ("xxx@live.de", "Test", "This is the message.")
 end

i have edited & tried your version of mail.cfg still getting same error

@Sharpy do you have a firewall, Antivirus or Avast Mail Shield?

They could intercepting your request.

https://javaee.github.io/javamail/FAQ#installcert

1 Like

i will disable all firewalls and antivirus try again

Disabled Anti Virus the message sent what do i need too add as an exception so i can turn my AV back on

is it just add the hostname

Which antivirus? http://bfy.tw/Gert

Avast

@Sharpy first hit in my link above

i know how to use google m8 its pretty simple i also know how too add an exception in an AV thats pretty simple too what i asked was what needs to be inputted into the exception hostname port ect

Thanks for your help with that i dont think i would ever have thought it was AV i had already tried disable firewall i will solve the rest appreciate that

Thanks Rich that also helped

I don’t have Avast so i can not tell you how to do this. But i would suggest to whitelist smtp.gmail.com?

Best i found was:

Turning off the scanning of outgoing smtp emails in Avast. Go to Settings>Components>Mail Shield (click customize) and then untick “scan outbound mail (SMTP)”.

I have just tried adding smtp.gmail.com and smtp.gmail.com:456
still getting the error but works perfect once AV disabled i will do some research now i know whats wrong i don’t think i’m running the mail shield

avast added https:smtp.gmail.com

@Sharpy maybe there is a way to see what avast has blocked when turned on and there you can get a bettter hint what to use to whitlist.

correction i am running the mail shield there are 4 shields on avast 3 can be left enabled you have to disable the mail shield too allow the email too send i will look if you can see whats been blocked

i cant actually find a exception setting for the mail shield only that it scans inbound or outbound and you can disable them there

I think i have sorted it, it looks like the mail shield was just fully blocking port 465 after removing this port it works and the mail shield is still turned on would you recommend this approach

I would recommend TLS instead of SSL, so using port 587. As TLS is the predecessor of SSL.

Further more i can’t comment, but i think ist one of the smaller wholes you can dig. But it will also enable bots to use you PC to send mails over this port when you get infected. Which the outgoing mail shield should try to prevent i think.

I think i will take the risk of bots at the moment i will look into it more soon i may already be using TLS as i left SSL commented out i’m just glad its working and can stop using IFTTT for emails

Thanks for your help on that i was completely stuck i appreciate that