0

After hours of googling I got the code for sending email from JSP page from tutorialpoints web site, I tried this entire code as mentioned in the tutorial also added recommended jar files. But after every setting with actual email id like this -

// Recipient's email ID needs to be mentioned.
   String to = "vishaldb28@gmail.com";
   // Sender's email ID needs to be mentioned
   String from = "info@cbsecsnip.in";
   // Assuming you are sending email from localhost
   String host = "localhost";
   // Get system properties object
   Properties properties = System.getProperties();

   // Setup mail server
   properties.setProperty("mail.cbsecsnip.in", host);
   properties.setProperty("mail.user", "info@cbsecsnip.in");
   properties.setProperty("mail.password", "password");
   // Get the default Session object.
   Session mailSession = Session.getDefaultInstance(properties);

I am getting exception -

javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.SendFailedException: Invalid Addresses; nested exception is: class javax.mail.SendFailedException: 553 We do not relay non-local mail, sorry.

at javax.mail.Transport.send0(Transport.java:218) at javax.mail.Transport.send(Transport.java:80) at org.apache.jsp.addstudent_jsp._jspService(addstudent_jsp.java:168) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:269) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1773) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

Please if anybody can help me to come out from this exception.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
cbsecommerce
  • 47
  • 1
  • 6

1 Answers1

0

javax.mail.SendFailedException: 553 We do not relay non-local mail, sorry.

You need to use an SMTP-server which you are allowed to forward mail through. If you have root access to the system you are running on, you just need to reconfigure the SMTP-server to allow relaying (in a safe manner, not for all the internet). If not, talk to those who do.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Which property I need to modify - Kindly see the edited part of original post – cbsecommerce Mar 06 '16 at 19:41
  • The problem isn't in your code, it's in the mail server. If you own the mail server, you need to reconfigure it to allow relaying. If you don't own the mail server, you need to use a different mail server that allows relaying. – Bill Shannon Mar 06 '16 at 19:50
  • "Relaying" means sending mails through the server, where neither the sender email or the recipient email "belongs" to the server. In other words, it is just expected to relay it elsewhere. – Thorbjørn Ravn Andersen Mar 06 '16 at 22:04