我有一个项目在完成过程时使用电子邮件通知。 但有时当我的计算机失去与互联网的连接时,我的进程会出现异常并停止...... 于是我在JAVA中搜索了重发邮件的解决方案,但没有找到。
有人知道吗? JAVA API?或者其他方法~
感谢您的帮助!
Properties prop = System.getProperties();
prop.put("mail.smtp.host", host);
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.port", port);
Session session1 = Session.getDefaultInstance(prop, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, password);
}
});
Message mailmessage = new MimeMessage(session1);
mailmessage.setFrom(new InternetAddress(from));
mailmessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
mailmessage.setSubject(subject);
mailmessage.setText(text);
Transport.send(mailmessage);
最佳答案
在计算机上安装 SMTP 服务,然后将 mail.smtp.host
设置为 localhost
。
SMTP 服务将尝试重新发送电子邮件,直到放弃(可配置)。
关于java - 我可以用java重新发送邮件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53292561/