Last week I have started working with IMAP mailbox manipulations in TomEE 1.7.0 environment (which contains Geronimo JavaMail 1.4_1.8.3 implementation) connecting to MS Exchange 2007 mail server and I have met some strange behaviour. Based on Google search I have found many others facing into the same difficulties.
when the following IMAP command is executed on an IMAP connection:
a28 APPEND FolderName () "29-Jun-2015 15:01:29 +0200" {7166}
+ Ready for additional command text.
the following exception rises:
org.apache.geronimo.javamail.util.CommandFailedException: Error response received on a IMAP continued command: + Ready for additional command text.
at org.apache.geronimo.javamail.store.imap.connection.IMAPCommand.writeTo(IMAPCommand.java:205) ~[geronimo-javamail_1.4_mail-1.8.4.jar:1.8.4]
at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.sendCommand(IMAPConnection.java:319) ~[geronimo-javamail_1.4_mail-1.8.4.jar:1.8.4]
at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.sendSimpleCommand(IMAPConnection.java:287) ~[geronimo-javamail_1.4_mail-1.8.4.jar:1.8.4]
at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.appendMessage(IMAPConnection.java:1425) ~[geronimo-javamail_1.4_mail-1.8.4.jar:1.8.4]
at org.apache.geronimo.javamail.store.imap.IMAPFolder.appendMessage(IMAPFolder.java:1564) ~[geronimo-javamail_1.4_mail-1.8.4.jar:1.8.4]
at org.apache.geronimo.javamail.store.imap.IMAPFolder.appendMessages(IMAPFolder.java:988) ~[geronimo-javamail_1.4_mail-1.8.4.jar:1.8.4]
The code is quite simple:
@LocalBean
@Stateless
public class ImapMailManager {
@Resource(name = "mail/myStore")
private Session storeSession;
public void addMessageToFolder(MimeMessage message, String targetFolderName) {
Store store = storeSession.getStore();
Properties props = storeSession.getProperties();
connectUsername = props.getProperty("mail.imaps.user");
connectPassword = props.getProperty("mail.imaps.password");
store.connect(connectUsername, connectPassword);
List<MimeMessage> messagesToCopy = new ArrayList<>();
messagesToCopy.add(message);
Message[] messages = new Message[messagesToCopy.size()];
// the exception raises at the following line:
store.getFolder(targetFolderName).appendMessages(
messagesToCopy.toArray(messages)
);
}
}
I have the following configuration in tomee.xml:
<Resource id="mail/myStore" type="javax.mail.Session">
mail.store.protocol=imaps
mail.imaps.host=mailserver.domain.com
mail.imaps.port=993
mail.imaps.auth=true
mail.imaps.user=user@domain.com
mail.imaps.password=thePassword
mail.imaps.auth.ntlm.disable=true
mail.imaps.auth.gssapi.disable=true
mail.imaps.auth.plain.disable=true
mail.debug=true
</Resource>
I have found a lot of thing on Google search which gave me some ideas and helped me just a small step forward:
This was the closest one with my authentication problem (because I had also that one):
- https://issues.apache.org/jira/browse/GERONIMO-6485
- https://issues.apache.org/jira/browse/GERONIMO-6526
I have also read this topic http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes
So I had to look many more search ... I have tried to patch, upgrade geronimo but not helped.
And finally I have found the right answer here at http://tomee-openejb.979440.n4.nabble.com/TomEE-JavaMail-problems-td4672429.html
So my conclusion was not using geronimo javaMail implementation any more but Oracle JavaMail reference implementation instead.
- So I have added geronimo-osgi-locator-1.1.jar (http://repo2.maven.org/maven2/org/apache/geronimo/specs/geronimo-osgi-locator/1.1/) to TOMEE/lib
- I removed geronimo-javamail_1.4_mail-1.8.3.jar from TOMEE/lib
- I have added javax.mail.jar (https://java.net/projects/javamail/pages/Home) to TOMEE/lib
And after that changes everything worked as it should.