java - 使用 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");
解决方案
推荐阅读
- c++ - 在 C++ 中使用 cin.getline() 后不从键盘输入
- flutter - 如何在向上滚动时隐藏应用栏但向下滚动时显示?
- visual-studio - 在 Visual Studio for Mac 上将 https 改回 http
- python - Python googlesearch API - 更改国家/地区位置并获取广告结果
- python - 如何在 Python Flask 中设置错误邮件
- javascript - 如何检查一个数字是否已经在数组中?
- php - Symfony Serializer xml 编码使用 CDATA 附加指定的属性
- r - 重新排序因子 llm
- android - 无法在android的videoview中播放来自url的视频如何在videoview中播放来自URL的视频?
- reactjs - 得到太阳年的反应