gpt4 book ai didi

java - java间歇性发送电子邮件

转载 作者:行者123 更新时间:2023-11-30 07:41:16 25 4
gpt4 key购买 nike

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.office365.com");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");//As discussed but does not work if the leave
props.put("mail.smtp.port", "587");



Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("mail@domi.cl","paswwd");
}
});

try {

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("mail@domi.cl"));

message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("mail@domi.cl"));
message.setSubject("Resumen envio masivo");
message.setText(mensajeMail);

Transport.send(message);

System.out.println("Done");

} catch (MessagingException e) {
throw new RuntimeException(e);
}

下面是堆栈跟踪:

Could not connect to SMTP host: smtp.office365.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused: connect
javax.faces.el.EvaluationException: java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.office365.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused: connect

最佳答案

该异常意味着您无法连接到服务器 smtp.office365.com 上的端口 587。使用 telnet 验证这一点:

telnet smtp.office365.com 587

此功能在您所在位置不起作用的可能原因是:

Java 中的代理设置配置错误

如果它不起作用并且您位于公司网络中,则很可能是防火墙导致了问题。另请检查密码和电子邮件是否正确。

也许它也适用于 TLS。你应该尝试一下。

关于java - java间歇性发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34665637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com