gpt4 book ai didi

Javamail 无法收到所有邮件

转载 作者:行者123 更新时间:2023-12-02 01:36:55 28 4
gpt4 key购买 nike

我试图获取我的 Gmail 的所有邮件,但只能获取 250 封。根据 https://javaee.github.io/javamail/FAQ#gmailsettings ,我已经将邮件数量限制设置为 1000,但它仍然只能获取 250 封邮件。这是我的代码

import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;

public class Getreply {

public static void check() {

String host = "pop.gmail.com";
String mailStoreType = "pop3";
String username = "";
String password = "";
try {

//create properties field
Properties properties = new Properties();

properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "995");
properties.put("mail.pop3.starttls.enable", "true");
Session emailSession = Session.getDefaultInstance(properties);

//create the POP3 store object and connect with the pop server
Store store = emailSession.getStore("pop3s");

store.connect(host, username, password);

//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];
Object body = message.getContent();
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: " + body );

}

//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();
}
}

}

有谁知道我怎样才能得到全部?

最佳答案

检查 Gmail 中的 POP 设置或切换到 IMAP。

关于Javamail 无法收到所有邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55105822/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com