Reputation: 13
I use
receiveEmailAndMarkSeen(EmailFilter.filter().flag(Flags.Flag.SEEN,true));
to filter the message which I don't read, but the function returns empty array. If I set false
it returns all the message.
I test many times, I don't know what's wrong
Could someone help me?
Upvotes: 1
Views: 132
Reputation: 10604
This may depend on the target server. Are you using IMAP or POP server? IMAP is the one that usually works better with your use case.
Here is an example that worked for me:
ImapServer imapServer = MailServer.create()
.host("imap.gmail.com")
.ssl(true)
.auth("user", "password")
.buildImapMailServer();
ReceiveMailSession session = imapServer.createSession();
session.open();
ReceivedEmail[] mails =
session.receiveEmailAndMarkSeen(
EmailFilter.filter().flag(Flags.Flag.SEEN, false));
Arrays.stream(mails).map(CommonEmail::subject).forEach(System.out::println);
session.close();
My mailbox:
Program output:
p.s. try to download all emails and check the Flag
of received emails. Also, use IMAP.
Upvotes: 0