首页 > 解决方案 > 使用 java 代码发送邮件在少数网络上工作,而不是在少数网络上工作?

问题描述

我已经尝试了很多方法来解决这个问题。我已经使用了 3 个端口(25,465,587),但都没有使用少数网络。错误消息是

“java.mail.MessageingException:无法连接到 SMTP 主机:smtp.gmail.com,端口:587;嵌套异常是:java.net.ConnectException:无法连接到 smtp.gmail.com/2404:6800:4008: 90000 毫秒后 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");

标签: javajakarta-mail

解决方案


推荐阅读