【问题标题】:I am not able to read email content using javax mail imap because less secure apps is no longer available now as google declares on 30th May 2022我无法使用 javax 邮件 imap 阅读电子邮件内容,因为谷歌在 2022 年 5 月 30 日宣布,安全性较低的应用程序现在不再可用
【发布时间】:2022-08-23 13:54:47
【问题描述】:

我面临的错误internal.qaauto.framework.exceptions.EmailDriverException:javax.mail.AuthenticationFailedException:[AUTHENTICATIONFAILED] 无效凭据(失败)

at internal.qaauto.framework.drivers.email.ImapsEmailDriver.connect(ImapsEmailDriver.java:55)
at certainwebapptests.CreateSubAccount.setUp(CreateSubAccount.java:53)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

引起:javax.mail.AuthenticationFailedException:[AUTHENTICATIONFAILED] 无效凭据(失败) 在 com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:661) 在 javax.mail.Service.connect(Service.java:295) 在 internal.qaauto.framework.drivers.email.ImapsEmailDriver.connect(ImapsEmailDriver.java:45) ... 24 更多

这是我的代码尝试 { 属性 connectionProperties = new Properties();

        // Set IMAPS as store protocol


        connectionProperties.put(\"mail.store.protocol\", \"imaps\");
        connectionProperties.put(\"mail.imaps.ssl.checkserveridentity\", \"false\");

        // Create a session with mail server
        session = Session.getDefaultInstance(connectionProperties);

        // Get the Store, which is JavaMail name for the entity that holds the mails.
        store = session.getStore(\"imaps\");

        // Connect the recently created Store
        reporter.debug(\"Connecting to \" + MAIL_HOSTNAME + \":\" + IMAP_PORT + \" using \" + MAIL_USER + \"/\" + MAIL_PASSWORD);
        store.connect(MAIL_HOSTNAME, IMAP_PORT, MAIL_USER, MAIL_PASSWORD);

        // Check that connection was successful
        checkConnection();

        // Select Inbox folder
        selectFolder(\"Inbox\");
    } catch (MessagingException e) {
        reporter.error(\"Unable to connect to mail server \" + MAIL_HOSTNAME + \" through port \" + IMAP_PORT + \". Using \"
                + MAIL_USER + \"/\" + MAIL_PASSWORD + \". Reason: \" + e.getMessage());
        throw new RuntimeException(e);
    }

标签: java email selenium-webdriver gmail-imap


【解决方案1】:

您必须使用不同的身份验证方法。 OAuth2 或app password。请参阅this question,这很可能是其副本。

【讨论】:

  • 提供的解决方案不起作用,尝试使用 oauth2 并创建 16 位应用程序密码都不起作用
  • Oauth2 遇到什么错误?
【解决方案2】:

您必须创建和使用应用程序密码

转到您的谷歌Account。 选择安全。 在“登录 Google”下,选择应用密码。您可能需要登录。如果您没有此选项或未为您的帐户设置两步验证。

在底部,选择选择应用程序并选择您使用的应用程序,然后选择设备并选择您正在使用的设备,然后选择生成。 按照说明输入应用密码。应用程序密码是设备上黄色栏中的 16 个字符的代码。点击完成。

【讨论】:

    猜你喜欢
    • 2023-01-13
    • 2022-06-11
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 2014-05-31
    • 1970-01-01
    • 2022-07-19
    相关资源
    最近更新 更多