//这是我的发送邮件代码
  public int sendMail(String userMail,String sub,String content)
  {
      try {
          Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
          final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
          // Get a Properties object
          Properties props = System.getProperties();
          props.setProperty("mail.smtp.host", "smtp.gmail.com");
          props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
          props.setProperty("mail.smtp.socketFactory.fallback", "false");
          props.setProperty("mail.smtp.starttls.enable", "true");
          props.setProperty("mail.smtp.startssl.enable", "true");
          props.setProperty("mail.smtp.port", "465");
          props.put("mail.smtp.auth", "true");
          final String username = "[email protected]";
          final String password = "888888";
          Session session = Session.getDefaultInstance(props, new Authenticator()
          {
              protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication(username, password);
              }
          }
          );          // -- Create a new message --
          Message msg = new MimeMessage(session);          // -- Set the FROM and TO fields --
          msg.setFrom(new InternetAddress(username));
          msg.setRecipients(Message.RecipientType.TO,
          InternetAddress.parse(userMail,false));
          msg.setSubject(sub);
          msg.setText(content);
          msg.setSentDate(new Date());
          Transport.send(msg);          System.out.println("email is sent");
          return 1;
      } catch (Exception ex) {
          ex.printStackTrace();
          return 0;
      }

解决方案 »

  1.   

    从网络分析一下原因
    telnet smtp.gmail.com 465
    看看连接情况,可以尝试用命令行发送一篇邮件测试一下
      

  2.   

    Could not connect to SMTP host: smtp.gmail.com, port: 465 
    估计可能的原因
    1 你的weblogic 的内部安全机制(我不懂,不说了)
    2 你的机器装了防火墙,不允许weblogic访问外网的465端口
    3 你换一个SMTP看看,如果能用,可以肯定是google那面把什么给屏蔽了。