javax.mail.internet.MimeMessage无法转换为javax.mail.Message

时间:2019-04-01 13:48:21

标签: java javamail liferay-7 mime-message message-listener

javax.mail.Message mimeMessage = (javax.mail.Message)array[1];抛出

com.liferay.portal.kernel.messaging.MessageListenerException: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.Message.
Caused by: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.Message
public void Receive(Message message) throws Exception {

    Object[] array = (Object[])message.getPayload();

    FileVersion sourceFileVersion = (FileVersion)array[0];
    javax.mail.Message mimeMessage = (javax.mail.Message)array[1];

1 个答案:

答案 0 :(得分:-2)

那是因为您正在将MimeMessage投射到Message,请尝试如下更改

MimeMessage mimeMessage = (javax.mail.internet.MimeMessage) array[1];