Java 使用Gmail服务器&x27下载电子邮件;身份验证失败';

Java 使用Gmail服务器&x27下载电子邮件;身份验证失败';,java,download,email-attachments,gmail-api,pop3,Java,Download,Email Attachments,Gmail Api,Pop3,我想使用Gmail服务器下载电子邮件,首先我需要连接它,我正在使用Pop3 Gmail服务器,但出现“身份验证失败”错误。连接代码为: Properties properties = new Properties(); // server setting properties.put("mail.pop3.host",host); properties.put("mail.pop3.port",port); // SSL setting p

我想使用Gmail服务器下载电子邮件,首先我需要连接它,我正在使用Pop3 Gmail服务器,但出现“身份验证失败”错误。连接代码为:

        Properties properties = new Properties();
    // server setting
    properties.put("mail.pop3.host",host);
    properties.put("mail.pop3.port",port);
    // SSL setting
    properties.setProperty("mail.pop3.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
    properties.setProperty("mail.pop3.socketFactory.fallback", "false");
    properties.setProperty("mail.pop3.socketFactory.port",
            String.valueOf(port));
    Session session = Session.getDefaultInstance(properties);
    try {
        // connects to the message store
        Store store = session.getStore("pop3s");
        store.connect(userName, password);    //error at this line

问题是由于Gmail中的安全设置,如果您添加

emailSession.setDebug(true);
您将实际获得一个指向错误消息的链接


还发现了

谢谢,bt它不起作用,问题是Avast防病毒,它阻止了与邮件服务器的连接。

可能是bt的重复,bt它不起作用@KennetError:javax.mail.MessagineException:connect失败;嵌套异常为:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径生成失败:sun.security.provider.certpath.SunCertPathBuilderException:无法在javax.mail.Service.connect的com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:213)中找到请求目标的有效认证路径(Service.java:345)在javax.mail.Service.connect(Service.java:226)在javax.mail.Service.connect(Service.java:246)发现同样的问题,不知道为什么,“stor.connect(用户名、密码);”不起作用