File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Email not sending from my website Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Email not sending from my website" Watch "Email not sending from my website" New topic
Author

Email not sending from my website

Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Hi all experts.

I am a java developer. I developed one website (http://www.madhuram.co/welcome.do) under java platform. my website contains Contact us page. "http://www.madhuram.co/ContactUs.do". By filling form and press submit it need to send email on specify email address. but on click of submit button it generates error 500. But with same code it works fine on my local environment. following is the code snippet.


As i said, with same code it works fine on my local environment but it gives following error on web server.

ERROR

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.sendMail_jsp._jspService(sendMail_jsp.java:140)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972)
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
javax.mail.Service.connect(Service.java:317)
javax.mail.Service.connect(Service.java:176)
javax.mail.Service.connect(Service.java:125)
javax.mail.Transport.send0(Transport.java:194)
javax.mail.Transport.send(Transport.java:124)
org.apache.jsp.sendMail_jsp._jspService(sendMail_jsp.java:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.net.ConnectException: Connection refused
java.net.PlainSocketImpl.socketConnect(Native Method)
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
java.net.Socket.connect(Socket.java:529)
java.net.Socket.connect(Socket.java:478)
com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319)
com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
javax.mail.Service.connect(Service.java:317)
javax.mail.Service.connect(Service.java:176)
javax.mail.Service.connect(Service.java:125)
javax.mail.Transport.send0(Transport.java:194)
javax.mail.Transport.send(Transport.java:124)
org.apache.jsp.sendMail_jsp._jspService(sendMail_jsp.java:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


Please provide me help, i tried lot but i don't got any solution.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860



Your server may have some firewall, port rules in place.
Or gmail is refusing your connection because your application is not "signed in".

Actually your code has port 25, but I'm betting that the host is mapping that to 587.
Providers do this to avoid spambots.

WP
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

Another possible reason is you haven't enabled SMTP in your Gmail account setting.


PM Me If You Want to get Urgent Help on Java Programming
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Email not sending from my website
 
Similar Threads
java.lang.ClassNotFoundException: javax.mail.Message
Help with java mail.
send email using gmail account
NoSuchProviderException: smtp
how to send mail using gmail server