使用JSP

时间:2016-03-06 19:24:35

标签: java jsp javamail javax.mail.address

经过几个小时的谷歌搜索后,我从tutorialpoints web site获得了从JSP页面发送电子邮件的代码,我尝试了整个代码,如教程中所提到的,还添加了推荐的jar文件。但是在每个设置都有这样的实际电子邮件ID之后 -

// 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);

我得到例外 -

  

javax.mail.SendFailedException:发送失败;嵌套异常是:     class javax.mail.SendFailedException:无效的地址;嵌套   异常是:class javax.mail.SendFailedException:553我们没有   转发非本地邮件,抱歉。

     

在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 at   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:722)at at   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)     在   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:722)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)     在   org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:269)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:515)     在   org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:1773)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:603)     在java.lang.Thread.run(Thread.java:722)

如果有人可以帮助我摆脱这种例外。

1 个答案:

答案 0 :(得分:0)

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

您需要使用允许转发邮件的SMTP服务器。如果您对正在运行的系统具有root访问权限,则只需重新配置SMTP服务器以允许中继(以安全的方式,而不是所有Internet)。如果没有,请与那些做的人交谈。