使用Java代码发送邮件在少数网络上工作而不在少数网络上工作?

时间:2019-06-01 06:08:09

标签: java javamail

我尝试了很多方法来解决此问题。我使用了3个端口(25,465,587),都无法在少数网络上工作。错误消息是

  

“ java.mail.MessageingException:无法连接到SMTP主机:   smtp.gmail.com,端口:587;嵌套的异常是:   java.net.ConnectException:连接失败   90000ms之后smtp.gmail.com/2404:6800:4008:c00::6d(端口587):是   连接失败:ENETUNREACH(网络不可达)”

  Session session = Session.getInstance(props, this);
  MimeMessage msg = new MimeMessage(session); 
  msg.setFrom(new InternetAddress(_from)); 
  InternetAddress[] addressTo = new InternetAddress[_to.length]; 
  for (int i = 0; i < _to.length; i++) { 
    addressTo[i] = new InternetAddress(_to[i]); 
  } 
    msg.setRecipients(MimeMessage.RecipientType.TO, addressTo);
  msg.setSubject(_subject); 
  msg.setSentDate(new Date());
  BodyPart messageBodyPart = new MimeBodyPart();
  messageBodyPart.setText(_body);
  _multipart.addBodyPart(messageBodyPart);
  msg.setContent(_multipart);
  Transport.send(msg);     
props.put("mail.smtp.host", _host); 
props.put("mail.smtp.port", _port);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");

0 个答案:

没有答案