appendMessages方法在javax邮件中不起作用

时间:2013-04-11 09:41:45

标签: java apache api email james

我想在用户文件夹中附加一条消息,但如果我调用appendMessages()方法,它的工作时间太长,但不会停止。然后邮件服务器显示以下消息:“注销客户端test1@mydomain.com,因为它闲置了很长时间......”并停止连接池。我正在使用apache 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类状态截图:

enter image description here

这是詹姆斯州:

enter image description here

有谁知道我的错误在哪里?

0 个答案:

没有答案