我无法使用Javax Mail IMAP阅读电子邮件内容,因为现在不再可用安全应用程序,因为Google在2022年5月30日声明
我面临的错误 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引起 在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);
}
Error which i faced
internal.qaauto.framework.exceptions.EmailDriverException: javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid credentials (Failure)
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)
Caused by: javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid credentials (Failure)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:661)
at javax.mail.Service.connect(Service.java:295)
at internal.qaauto.framework.drivers.email.ImapsEmailDriver.connect(ImapsEmailDriver.java:45)
... 24 more
Here is my code
try {
Properties 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须创建&使用应用程序密码
转到您的Google 帐户。
选择安全性。
在“登录到Google”下,选择应用程序密码。您可能需要登录。如果您没有此选项或未为您的帐户设置2步验证。
在底部,选择“选择应用程序”,然后选择您使用的应用程序,然后选择设备,然后选择您使用的设备然后生成。
按照说明输入应用程序密码。应用程序密码是设备上黄色栏中的16个字符代码。叮当响了。
如果您获得了证书错误,请尝试以下操作:
如果要获得TTL/SSL错误,请尝试以下操作:
You have to Create & use App Passwords
Go to your Google Account.
Select Security.
Under "Signing in to Google," select App Passwords. You may need to sign in. If you don’t have this option or 2-Step Verification is not set up for your account.
At the bottom, choose Select app and choose the app you using and then Select device and choose the device you’re using and then Generate.
Follow the instructions to enter the App Password. The App Password is the 16-character code in the yellow bar on your device. Clink on Done.
If you are getting cert error try this :
If you are getting TTL/SSL error try this:
您必须使用不同的身份验证方法。 oauth2或a app密码。请参阅这个问题重复。
You have to use a different authentication method. Either OAuth2 or an app password. See this question which this is likely a duplicate of.