Java Mail异常错误

时间:2014-02-20 19:47:52

标签: java javamail

错误堆栈跟踪 -

 at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at Report.sendmail(Report.java:100)
    at Report.main(Report.java:301)
Caused by: java.net.SocketException: Network is unreachable: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

代码 -

Properties properties = System.getProperties();
         properties.setProperty("mail.smtp.host", "172.16.200.60");
         properties. put("mail.smtp.port", "25");
         properties.put("mail.smtp.auth", "false");
         properties.put("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
         properties.setProperty("mail.smtp.ssl.trust", "smtpserver");
         properties.put("mail.smtp.starttls.enable", "true");
         properties.put("java.net.preferIPv4Stack" , "true");
         properties.put("mail.smtp.socketFactory.class",
         "javax.net.ssl.SSLSocketFactory");


         Session session = Session.getInstance(properties);
         try{
             MimeMessage message = new MimeMessage(session);
             message.setFrom(new InternetAddress(fromAddress));
             String[] toAddress = toemailAddress.toArray(new String[toemailAddress.size()]);
            // System.out.println(Arrays.toString(toAddress).replace("[", "") .replace("]", "").replace(",",","));
             message.setRecipients(Message.RecipientType.TO,
                     InternetAddress.parse(Arrays.toString(toAddress).replace("[", "") .replace("]", "").replace(" ","")));
             String[] ccAddress = ccemailAddress.toArray(new String[ccemailAddress.size()]);

             message.setRecipients(Message.RecipientType.CC, 
                     InternetAddress.parse(Arrays.toString(ccAddress).replace("[", "") .replace("]", "")));
             message.setSubject(subject);

             MimeBodyPart  messageBodyPart = new MimeBodyPart();
             String body ="Please find attached Shipping documents for Transfer Order '"+xoNumber+"'.";
             messageBodyPart.setContent(body, "text/html");

             Multipart multipart = new MimeMultipart();
             multipart.addBodyPart(messageBodyPart);

             for (String filename : filesfromFolders){
                        MimeBodyPart attachPart = new MimeBodyPart();
                        attachPart.attachFile(filename);
                        multipart.addBodyPart(attachPart);
             }

             message.setContent(multipart);
             Transport.send(message);
             System.out.println("Email sent  successfully to ");




         }
         catch (Exception mex) {
              mex.printStackTrace();
          }

我做了以下事情

  1. 向信任主机添加属性
  2. 停止IPV4但不起作用。
  3. 我将java 7转换为java 6但没有使用
  4. 打开端口25但不起作用
  5. IP地址正在运行telnet命令
  6. 但不起作用

1 个答案:

答案 0 :(得分:0)

由于某种原因,网络层无法访问172.16.200.60地址。

我建议您重新验证“telnet 172.16.200.60 25”的工作原理。如果没有,则需要修复网络配置(TCP / IP路由,DHCP服务器)。

如果telnet有效,我建议您查看您的JVM是否配置为使用所显示源之外的任何类型的代理,因为如果代理无法访问,则可以报告错误。