如何通过javamail api检查我的hotmail帐户中有多少未读邮件?
我正在尝试从我的hotamil帐户获取未读邮件号码。我使用,但我有一个问题,它总是返回我的收件箱中所有现有的电子邮件号码。我在这里分享我的代码:如何通过javamail api检查我的hotmail帐户中有多少未读邮件?,java,jakarta-mail,Java,Jakarta Mail,我正在尝试从我的hotamil帐户获取未读邮件号码。我使用,但我有一个问题,它总是返回我的收件箱中所有现有的电子邮件号码。我在这里分享我的代码: public class testEmail { public static void check(String host, String storeType, String user, String password) { try {
public class testEmail {
public static void check(String host, String storeType, String user,
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");
// properties.put("mail.imap.ssl.enable", "true");
Session emailSession = Session.getInstance(properties, null);
emailSession.setDebug(false);
//create the POP3 store object and connect with the pop server
Store store = emailSession.getStore("pop3s");
store.connect(host, user, password);
//create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
//for count the unread email
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
Message messages[] = emailFolder.search(ft);
System.out.println("No. of Unread Messages : " + messages.length);
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-mail.outlook.com";// change accordingly
String mailStoreType = "pop3";
String username = "abc@hotmail.com";// change accordingly
String password = "abc";// change accordingly
check(host, mailStoreType, username, password);
}
}
如果我使用
FlagTerm(新标志(Flags.Flag.SEEN),则为true代码>其返回值0。此问题与代码或Hotmail帐户有关。提前谢谢 Flags.Flag.SEEN
在POP3中无法正常工作,因此我将其更改为IMAP。如果mail.imap.port=993
不工作,则使用25。答案是关于hotmail的 Flags.Flag.SEEN
在POP3中无法正常工作,因此我将其更改为IMAP。如果mail.imap.port=993
不工作,则使用25。答案是关于hotmail的 请尝试Folder.GetUnderMessageCount()方法。我也尝试了此方法,但结果相同。请尝试Folder.GetUnderMessageCount()方法。我也尝试了此方法,但结果相同。如文档中所述,。如文档中所述。