javax.mail.AuthenticationFailedException:[AUTH]需要Web登录
我使用Java构建了一个应用程序来读取电子邮件。在过去的几天里,它没有出现任何错误。但是今天突然出现了这样一个错误javax.mail.AuthenticationFailedException:[AUTH]需要Web登录,java,gmail,jakarta-mail,pop3,Java,Gmail,Jakarta Mail,Pop3,我使用Java构建了一个应用程序来读取电子邮件。在过去的几天里,它没有出现任何错误。但是今天突然出现了这样一个错误 javax.mail.AuthenticationFailedException: [AUTH] Web login required: https://support.google.com/mail/answer/78754 at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207)
javax.mail.AuthenticationFailedException: [AUTH] Web login required: https://support.google.com/mail/answer/78754
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at MailReader.readMail(MailReader.java:44)
at MailReader.run(MailReader.java:32)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
我想不出怎么解决这个问题。我没有设置双向身份验证。而且我还允许使用不太安全的应用程序。所以我不知道怎么回事。有人能帮我吗?我非常感谢
这是我正在使用的代码
String host = "pop.gmail.com";
String username = "somename@gmail.com";
String password = "password";
Properties prop = new Properties();
Session session = Session.getInstance(prop, null);
Store store = session.getStore("pop3s");
store.connect(host, username, password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
我的工作代码段如下所示:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
public class CheckingMails {
public static void check(String host, String user, String password)
{
try {
// create properties field
Properties properties = new Properties();
properties.put("mail.pop3s.host", host);
properties.put("mail.pop3s.port", "995");
properties.put("mail.pop3s.starttls.enable", "true");
// Setup authentication, get session
Session session = Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
// session.setDebug(true);
// create the POP3 store object and connect with the pop server
Store store = session.getStore("pop3s");
store.connect();
// create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
for (int i = 0, n = messages.length; i < n; i++) {
Message message = messages[i];
System.out.println("---------------------------------");
System.out.println("Email Number " + (i + 1));
System.out.println("Subject: " + message.getSubject());
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Text: " + message.getContent().toString());
}
// close the store and folder objects
emailFolder.close(false);
store.close();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String host = "pop.gmail.com";
String username = "abc@gmail.com";// change accordingly
String password = "*****";// change accordingly
check(host, username, password);
}
}
import java.util.Properties;
导入javax.mail.Authenticator;
导入javax.mail.Folder;
导入javax.mail.Message;
导入javax.mail.MessaginException;
导入javax.mail.NoSuchProviderException;
导入javax.mail.PasswordAuthentication;
导入javax.mail.Session;
导入javax.mail.Store;
公共类检查邮件{
公共静态无效检查(字符串主机、字符串用户、字符串密码)
{
试一试{
//创建属性字段
属性=新属性();
properties.put(“mail.pop3s.host”,host);
properties.put(“mail.pop3s.port”,“995”);
properties.put(“mail.pop3s.starttls.enable”、“true”);
//设置身份验证,获取会话
Session Session=Session.getInstance(属性,
新的javax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新的PasswordAuthentication(用户、密码);
}
});
//session.setDebug(true);
//创建POP3存储对象并连接pop服务器
Store Store=session.getStore(“pop3s”);
store.connect();
//创建文件夹对象并将其打开
文件夹emailFolder=store.getFolder(“收件箱”);
emailFolder.open(文件夹只读);
//从数组中的文件夹中检索邮件并打印
Message[]messages=emailFolder.getMessages();
System.out.println(“messages.length----”+messages.length);
for(int i=0,n=messages.length;i
我的工作代码段如下所示:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
public class CheckingMails {
public static void check(String host, String user, String password)
{
try {
// create properties field
Properties properties = new Properties();
properties.put("mail.pop3s.host", host);
properties.put("mail.pop3s.port", "995");
properties.put("mail.pop3s.starttls.enable", "true");
// Setup authentication, get session
Session session = Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
// session.setDebug(true);
// create the POP3 store object and connect with the pop server
Store store = session.getStore("pop3s");
store.connect();
// create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
for (int i = 0, n = messages.length; i < n; i++) {
Message message = messages[i];
System.out.println("---------------------------------");
System.out.println("Email Number " + (i + 1));
System.out.println("Subject: " + message.getSubject());
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Text: " + message.getContent().toString());
}
// close the store and folder objects
emailFolder.close(false);
store.close();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String host = "pop.gmail.com";
String username = "abc@gmail.com";// change accordingly
String password = "*****";// change accordingly
check(host, username, password);
}
}
import java.util.Properties;
导入javax.mail.Authenticator;
导入javax.mail.Folder;
导入javax.mail.Message;
导入javax.mail.MessaginException;
导入javax.mail.NoSuchProviderException;
导入javax.mail.PasswordAuthentication;
导入javax.mail.Session;
导入javax.mail.Store;
公共类检查邮件{
公共静态无效检查(字符串主机、字符串用户、字符串密码)
{
试一试{
//创建属性字段
属性=新属性();
properties.put(“mail.pop3s.host”,host);
properties.put(“mail.pop3s.port”,“995”);
properties.put(“mail.pop3s.starttls.enable”、“true”);
//设置身份验证,获取会话
Session Session=Session.getInstance(属性,
新的javax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新的PasswordAuthentication(用户、密码);
}
});
//session.setDebug(true);
//创建POP3存储对象并连接pop服务器
Store Store=session.getStore(“pop3s”);
store.connect();
//创建文件夹对象并将其打开
文件夹emailFolder=store.getFolder(“收件箱”);
emailFolder.open(文件夹只读);
//从数组中的文件夹中检索邮件并打印
Message[]messages=emailFolder.getMessages();
System.out.println(“messages.length----”+messages.length);
for(int i=0,n=messages.length;i
该错误是由于谷歌的一个错误导致POP3服务无法正常工作。两天后就修好了
找不到官方声明,只有论坛帖子。有关资料来源:
,该错误是由于谷歌的一个错误导致POP3服务无法正常工作。两天后就修好了 找不到官方声明,只有论坛帖子。有关资料来源:
,我的问题是,虽然我设置了不太安全的e