我想将一条消息附加到用户文件夹,但是如果我调用 appendMessages() 方法,它会工作太久,但不会停止。然后邮件服务器显示此消息:“注销客户端 test1@mydomain.com,因为它闲置了很长时间......”并停止连接池。我正在使用 apache james 邮件服务器。与 james 的连接和打开“QUARANTINE”文件夹工作正常,但 appendMessages() 不起作用。
这是我的代码:
final String login = "test1@mydomain.com";
final String passw = "test1";
String toAddress = "test2@mydomen.com";
Properties properties = new Properties();
properties.setProperty("mail.store.protocol", "imap");
properties.setProperty("mail.imap.host", myhost);
properties.setProperty("mail.imap.port", "1243");
Session session = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(login, passw);
}
});
try {
MimeMessage mimeMessage;
mimeMessage = new MimeMessage(session);
Address[] to = {new InternetAddress(toAddress)};
mimeMessage.setRecipients(RecipientType.TO, to);
mimeMessage.setSubject("TEST_SUBJECT");
MimeMultipart mp = new MimeMultipart();
MimeBodyPart newPart = new MimeBodyPart();
newPart.setText("MESSAGE_BODY");
mp.addBodyPart(newPart);
//add image file
newPart = new MimeBodyPart();
File imgFile = new File("Attachments//test.png");
FileDataSource fds = new FileDataSource(imgFile);
newPart.setDataHandler(new DataHandler(fds));
newPart.setFileName(imgFile.getName());
newPart.setDisposition(BodyPart.ATTACHMENT);
mp.addBodyPart(newPart);
mimeMessage.setContent(mp);
Store store = session.getStore("imap");
store.connect(myhost, 1243 , login, passw);
Folder folder = (IMAPFolder) store.getFolder("QUARANTINE");
if (!folder.exists()) folder.create(Folder.HOLDS_MESSAGES);
folder.open(Folder.READ_WRITE);
folder.appendMessages(new Message[] {mimeMessage});
} catch (MessagingException e) {
e.printStackTrace();
}
这是java类状态截图:
这是詹姆斯状态:
有谁知道我的错误在哪里?