我开发了一个使用 SMTP 将消息发送到本地 Apache James 服务器的应用程序。运行一次程序大约需要 3-10 分钟。我让程序连续运行了几个小时进行性能测试,这在 Ubuntu 上运行良好。但是,当我在 Windows 10 上运行该程序时,我会在大约 10 分钟后收到以下堆栈跟踪。2-3小时运行时间:
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 451 4.0.0 Error processing message: The system cannot find the path specified
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2374)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:2095)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1301)
at org.bihealth.mi.easybus.implementations.email.ConnectionIMAP.send(ConnectionIMAP.java:294)
... 6 more
该问题发生在两个不同的 Windows 10 安装上,系统的防火墙已停止。和属性的编码send method
如下所示。如果发生错误,该方法会连续调用 10 次,每次发送重试之间的等待时间为 30 秒,然后才会引发上述异常。与消息“系统找不到指定路径”的许多其他问题的不同之处在于,该错误仅在有时(2-3 小时)发生,并非总是发生。
您是否有任何暗示潜在问题可能是什么?任何帮助深表感谢!
protected synchronized void send(String recipient, String subject, String body, Object attachment) throws BusException {
synchronized(propertiesSending) {
// Make sure we are ready to go
try {
if (session == null) {
session = Session.getInstance(propertiesSending);
}
} catch (Exception e) {
throw new BusException("Error establishing or keeping alive connection to mail server", e);
}
try {
// Create message
MimeMessage email = new MimeMessage(session);
// Add sender and recipient
email.setRecipient(RecipientType.TO, new InternetAddress(recipient));
email.setSender(new InternetAddress(getEmailAddress()));
email.setFrom(new InternetAddress(getEmailAddress()));
email.setSubject(subject);
// Add body
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
mimeBodyPart.setContent(body, "text/plain");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
// Add attachment
if (attachment != null) {
mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
byte[] attachmentBytes = getByteArrayOutputStream(attachment);
mimeBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(attachmentBytes, "application/octet-stream")));
mimeBodyPart.setFileName(FILENAME_MESSAGE);
multipart.addBodyPart(mimeBodyPart);
// Add statistics
Bus.numberMessagesSent.incrementAndGet();
Bus.totalSizeMessagesSent.addAndGet(attachmentBytes.length);
}
// Compose message
email.setContent(multipart);
// Send
Transport.send(email, getEmailAddress(), password);
logger.debug("Message sent logged", new Date(), "Message
sent logged", subject);
} catch (Exception e) {
throw new BusException("Unable to send message", e);
}
}
}
this.propertiesSending = new Properties();
this.propertiesSending.put("mail.user", getEmailAddress());
this.propertiesSending.put("mail.from", getEmailAddress());
this.propertiesSending.put("mail.transport.protocol", "smtp");
this.propertiesSending.put("mail.smtp.host", settings.getSMTPServer());
this.propertiesSending.put("mail.smtp.port", String.valueOf(settings.getSMTPPort()));
this.propertiesSending.put("mail.smtp.auth", "true");