javax.mail.SendFailedException:发送失败;嵌套的javax.net.ssl.SSLException:java.lang.RuntimeException:无法生成DH密钥对

时间:2017-07-28 07:29:53

标签: jsp javamail contact-form

<html>
<head>
<title>JSP JavaMail Example</title>
</head>
<body>
    <%@ page import="java.util.*"%>
    <%@ page import="javax.mail.*"%>
    <%@ page import="javax.mail.internet.*"%>
    <%@ page import="javax.activation.*"%>
    <%
        String to = request.getParameter("to");     
        String from = request.getParameter("email");
        String name = request.getParameter("name");
        String phone = request.getParameter("phone");
        String subject =request.getParameter("subject");
        String messageText = request.getParameter("message");
        //Get the session object  
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");



         Session session2 = Session.getInstance(props,
        new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("xyz@gmail.com", "abc2014!");//change accordingly
                //return new PasswordAuthentication("abc@gmail.com", "abc2014");//change accordingly                
            }
        }); 

        //compose message  
        try {
            MimeMessage message = new MimeMessage(session2);
            message.setFrom(new InternetAddress(from,name));//change accordingly  
            message.addRecipient(Message.RecipientType.TO,
                    new InternetAddress(to));
            message.setSubject(subject +" " +name);
            message.setSender(new InternetAddress(from,name));//change accordingly 
            message.setText(" Name: "+name+"\n Email :"+from+"\n Phone No :"+phone+"\n Message : "+messageText);

            System.out.println("before sent message" + to);

            //send message  
            Transport.send(message);

            System.out.println("message sent successfully" + to);

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }

        out.println("Mail was sent to " + to);
    %>

</body>
</html>

上面是我的Jsp文件,用于从我的网站联系表单发送邮件请求到我的电子邮件ID但是当我通过我的网站发送邮件时,我得到例外如下。当我在本地计算机上使用它但在部署在服务器上时抛出异常时工作正常。请帮忙解决这个问题。在此先感谢:

org.apache.catalina.core.StandardWrapperValve.invoke servlet [jsp]的Servlet.service()在上下文中与path []引发异常[在第62行处理JSP页面/sendMail.jsp时发生异常

59:                     System.out.println("message sent successfully" + to);
60:
61:             } catch (MessagingException e) {
62:                     throw new RuntimeException(e);
63:             }
64:
65:             out.println("Mail was sent to " + to);


Stacktrace:] with root cause
 javax.mail.SendFailedException: Sending failed;
  nested exception is:
        class javax.mail.MessagingException: Exception reading response;
  nested exception is:
        javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
        at javax.mail.Transport.send0(Transport.java:218)
        at javax.mail.Transport.send(Transport.java:80)
        at org.apache.jsp.sendMail_jsp._jspService(sendMail_jsp.java:154)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
        at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2440)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:722)

0 个答案:

没有答案