I have an email server to which people reply from emails that have been sent to them from that mail server.
Then I want to fetch these replies using the Java Mail API, but I am running into problems.
I am trying to fetch the replies via a ReceivedDateTerm
and an hourly cron, thus fetching all the replies in the last hour.
Let's say someone replied to an email sent to them yesterday at 3 p.m., today at 10 a.m. If I search for all emails since 9 a.m. today, I don’t get any results. However, if I search for all emails since yesterday 2 p.m., I get that reply, including the original email.
If I look into the reply (the Message
object), the receivedDate
field says 10 a.m. today, so I am really confused by why that email is not being found by my first query. Can it be that the reply is not being seen as a "real" email by Java Mail (or IMAP for that matter)?
Here's my relevant code:
private Message[] getMessagesSinceTimestampFromImapServer(Date since) throws MessagingException {
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
ReceivedDateTerm term = new ReceivedDateTerm(ComparisonTerm.GT, since);
return emailFolder.search(term);
}
I am using Java 11 and IMAP to connect to an Office 365 inbox.
Copyright License:
Author:「Collin Alpert」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/68844783/fetch-replies-with-java-mail