JavaMail - NoSuchMethodError:javax.mail.internet.ParameterList.combineSegments()V [英] JavaMail - NoSuchMethodError: javax.mail.internet.ParameterList.combineSegments()V

查看:1545
本文介绍了JavaMail - NoSuchMethodError:javax.mail.internet.ParameterList.combineSegments()V的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在自动化测试中使用它的内容,我需要阅读Gmail帐户的Sent Mail文件夹中的第一条消息(准确地说是字符串)。



我使用JavaMail来执行此操作,并使用IMAP协议:

  public static void main(String [] args ){
字符串invitationContent =没有邀请;

属性props = new Properties();
props.setProperty(mail.store.protocol,imaps);

尝试{
Session session = Session.getDefaultInstance(props,null);

Store store = session.getStore();
store.connect(imap.gmail.com,no-reply@companyname.com,somepassword);

文件夹收件箱= store.getFolder([Gmail] / Sent Mail);
inbox.open(Folder.READ_ONLY);
Message [] messages = inbox.getMessages();

地址userAddress = messages [messages.length-1] .getAllRecipients()[0];
System.out.println(userAddress.toString());
$ b $ inviteContent = messages [messages.length-1] .getContent()。toString();

inbox.close(true);
store.close();

} catch(Exception e){
e.printStackTrace();
}

System.out.println(invitationContent);
}

此代码成功地打印 userAddress ,但是当它到达消息时抛出这个异常:

 线程mainjava.lang中的异常。 NoSuchMethodError:javax.mail.internet.ParameterList.combineSegments()V 
at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:424)
at com.sun.mail。 imap.protocol.BODYSTRUCTURE。< init>(BODYSTRUCTURE.java:244)
at com.sun.mail.imap.protocol.FetchResponse.parseItem(FetchResponse.java:260)
at com.sun .mail.imap.protocol.FetchResponse.parse(FetchResponse.java:215)
at com.sun.mail.imap.protocol.FetchResponse。< init>(FetchResponse.java:96)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:350)
at com.sun.mail.iap.Protocol.command(Protocol.java:357)
at com。 sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1937)
at com.sun.m ail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1929)
at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:1504)
at com.sun。 mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1461)
at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:745)
at javax.mail.internet.MimeMessage。 getContent(MimeMessage.java:927)
at com.company.main.main(Main.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun。反射.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java: 606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

方法的文档此处表示正在调用它以合并多段名称的所有段。我很确定邮件不使用这些。为了理解问题,我发送了一封电子邮件,邮件中只有一个常规Gmail地址,一个简单的测试邮件主题和123作为内容,并且仍然有此异常。

$ b $你已经部署了一个不同于你编译的JavaMail Jars的版本,或者是一个内部自我不一致的版本。下载最新版本,然后重新开始一个干净的构建和部署。


I need to read (get as string, to be precise) the first message in the Sent Mail folder of a Gmail account, in order to use it's content in automated tests.

I'm using JavaMail to do so, with IMAP protocol:

public static void main(String[] args) {
        String invitationContent = "No invitation";

        Properties props = new Properties();
        props.setProperty("mail.store.protocol", "imaps");

        try {
            Session session = Session.getDefaultInstance(props, null);

            Store store = session.getStore();
            store.connect("imap.gmail.com", "no-reply@companyname.com", "somepassword");

            Folder inbox = store.getFolder("[Gmail]/Sent Mail");
            inbox.open(Folder.READ_ONLY);
            Message[] messages = inbox.getMessages();

            Address userAddress = messages[messages.length-1].getAllRecipients()[0];
            System.out.println(userAddress.toString());

            invitationContent = messages[messages.length-1].getContent().toString();

            inbox.close(true);
            store.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(invitationContent);
    }

This code successfully print the userAddress, however when it gets to the message this exception is thrown:

Exception in thread "main" java.lang.NoSuchMethodError: javax.mail.internet.ParameterList.combineSegments()V
    at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:424)
    at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:244)
    at com.sun.mail.imap.protocol.FetchResponse.parseItem(FetchResponse.java:260)
    at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:215)
    at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:96)
    at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:350)
    at com.sun.mail.iap.Protocol.command(Protocol.java:357)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1937)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1929)
    at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:1504)
    at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1461)
    at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:745)
    at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:927)
    at com.company.Main.main(Main.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

The documentation of the method here indicates that it is being called in order to combine all segments of multi-segment names. I'm pretty sure that the mail doesn't use those. In sake of understanding the problem I sent an email with just 1 "TO" that is a regular gmail address, a simple "test mail" subject and "123" as content, and still got this exception.

解决方案

You've deployed a different version of the JavaMail Jars from the ones you compiled against, or a set that is internally self-inconsistent. Download latest and start again with a clean build and deploy.

这篇关于JavaMail - NoSuchMethodError:javax.mail.internet.ParameterList.combineSegments()V的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆