Fetch replies with Java Mail

2021-08-19T16:54:21

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

About “Fetch replies with Java Mail” questions

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 problem...
How do i get the replies over a email message ? The replais from the sender and also the replies sent from the recipients. Also... Which one of these api is better to use? "com.sun.mail » jaka...
I have the following use case in my app: When a specific event happens in the app all interested users should be notified by email. Then if a user replies to the email, his reply should be shown in...
At work, when we send out an e-mail we have to type in the BCC field a certain address as well as click on the "message options" and type in "direct replies to:" another address. I want to add a b...
I'm trying to fetch both comments and replies of an article via one query using JOINs however not sure how to write it, so far I've got the comments but whenever I try to fetch the replies it stays
I had a look in the reference doc, and Spring seems to have pretty good support for sending mail. However, I need to login to a mail account, read the messages, and download any attachments. Is
do you know a way to create some king of plugin for automatic replies personalization? If an e-mail is something like: "Dear Sender, I am on vacation. I will be back on 27th of September&quot...
I'm using smtplib in python to send emails. I want to fetch any replies to these emails. Does imaplibprovide option to search inbox emails using message id of the parent email? I'm sure it does bec...
I am trying to get the email thread based on in-reply-to Id with help of below code. Imap.connect(config).then(function (connection) { return connection.openBox('INBOX').then(function () {...
I am currently using openPOP Library to fetch mails in my .net App. But it seems like there is no way in openPOP library to search a mail based on subject other than fetching the entire messages and

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.