Unable to send email from local server

M

mighty.tornado

Hi,

I set up a small web app and would like to send email, so I am using
google's smtp server. But I get an exception back. Here it is:
org.apache.commons.mail.EmailException: Sending the email to the
following serve
r failed : smtp.gmail.com:465
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:
873)
at org.apache.commons.mail.Email.send(Email.java:898)
at TimeTravelMailer.sendMessage(TimeTravelMailer.java :29)
at CreateAccountServlet.doPost(CreateAccountServlet.java:12)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java :
803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java :188)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:210)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:174)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineVal
ve.java:108)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:151)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:870)
at org.apache.coyote.http11.Http11BaseProtocol
$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:665)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:528)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadP
ool.java :685)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.mail.MessagingException: Could not connect to SMTP
host: smtp.g
mail.com, port: 465, response: -1
at
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1270)
at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:37
0)
at javax.mail.Service.connect(Service.java:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:
863)
... 19 more

What am I doing wrong?
 
G

Gordon Beaton

I set up a small web app and would like to send email, so I am using
google's smtp server. But I get an exception back. Here it is:
org.apache.commons.mail.EmailException: Sending the email to the
following server failed : smtp.gmail.com:465

Enable debugging in your JavaMail program. Post the debug output, and
maybe some code too.

/gordon

--
 
G

Greg R. Broderick

(e-mail address removed) wrote in @l77g2000hsb.googlegroups.com:
Hi,

I set up a small web app and would like to send email, so I am using
google's smtp server. But I get an exception back. Here it is:
[snippage]

Caused by: javax.mail.MessagingException: Could not connect to SMTP
host: smtp.g
mail.com, port: 465, response: -1
at
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1270)
at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:37
0)
at javax.mail.Service.connect(Service.java:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:
863)
... 19 more

What am I doing wrong?

The mail client software (your app) was unable to connect to the mail server
"smtp.gmail.com" on port 465, as the exception message stated. This could be
for any number of reasons, including:

- you have a firewall blocking your host from connecting to a remote host on
port 465.

- gmail's mail server is down and temporarily unreachable

- a router somewhere between your host and smtp.gmail.com is malfunctioning
and preventing a connection

- you aren't using SSL/TLS in your connection to smtp.gmail.com, as is
required, per <http://mail.google.com/support/bin/answer.py?answer=13287
&topic=1556>.

using telnet to connect to the remote host will allow you to determine if the
problem lies within your code (i.e. telnet is able to connect) or outside of
your code (i.e. telnet is also unable to connect). If the problem can be
localized to your code, then JavaMail has a debugging trace option that is
enabled by setting a system property named "mail.debug" to "true" (String
value). This will cause a full transcript of your session with the mail
server to be output to the console, and is quite useful in diagnosing issues
such as this.


In any case, this is something that your code should anticipate and handle
gracefully - your code is dependent upon a resource (the mail server) that is
outside of your control, therefore your code MUST handle this resource being
unavailable, either permanently or temporarily, gracefully.

Cheers!

--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 
R

Roman

Greg,
Thank you - it must have been SSL indeed.

Except I still get the same exception when I try to send from
https://localhost:8443 etc.

Is there a step I missed in configuring SSL on Tomcat?
I presume telnet connection to smtp.gmail.com 465 suceeded because
after I hit run-> telnet smtp.gmail.com 465 the screen went black with
no words or anything.
 
Joined
Aug 24, 2011
Messages
1
Reaction score
0
Error in javamail in server

Hello,
I am using java mail for send amil using smtp.gmail.com.

its working perfectly in local system........

when i am using this in remote server......its not connect to gmail.given error.


My error in below.










DEBUG: setDebug: JavaMail version 1.4.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s
mtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, p
ort: 465;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc
eption: PKIX path building failed: sun.security.provider.certpath.SunCertPathBui
lderException: unable to find valid certification path to requested target
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:52
5)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at com.struts.mailService.MailSend.sendMailService(MailSend.java:101)
at com.struts.member.Action.FriendAction.execute(FriendAction.java:138)
at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:148
2)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:731)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.Validator
Exception: PKIX path building failed: sun.security.provider.certpath.SunCertPath
BuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unkno
wn Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source
)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Un
known Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
rce)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java
:503)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:234)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
... 25 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find vali
d certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(
Unknown Source)
at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(
Unknown Source)
... 35 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown
Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 40 more




any body help me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top