上周我开始使用连接到MS Exchange 2007邮件服务器的TomEE 1.7.0环境(包含Geronimo JavaMail 1.4_1.8.3实现)中的IMAP邮箱操作,我遇到了一些奇怪的行为。基于谷歌搜索,我发现许多其他人面临同样的困难。
在IMAP连接上执行以下IMAP命令时:
a28 APPEND FolderName () "29-Jun-2015 15:01:29 +0200" {7166}
+ Ready for additional command text.
以下异常上升:
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]
代码非常简单:
@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)
);
}
}
我在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>
我在谷歌搜索上发现了很多东西给了我一些想法并帮助我向前迈了一小步:
这是与我的身份验证问题最接近的一个(因为我也有一个):
我还阅读了这个主题http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes
所以我不得不寻找更多的搜索...我试图修补,升级geronimo但没有帮助。
最后,我在http://tomee-openejb.979440.n4.nabble.com/TomEE-JavaMail-problems-td4672429.html
找到了正确答案所以我的结论是不再使用geronimo javaMail实现,而是使用Oracle JavaMail参考实现。
在那之后,一切都按原样运作。