Search code examples
gmailjakarta-mailimap

Gmail IMAP Javamail search returns no messages where web does


I'm working on load testing a web application that sends links via email. I have a gmail account set up specifically to be the recipient for this. When generating new accounts I add a guid to the recipient email (eg. loadtest_nmndbiwpdi@gmaildomain.com). When I execute the test it will either succeed entirely or fail entirely, but failures seem to be pretty random.

Here is my search snippet:

        if (!inbox.isOpen()) {
            inbox.open(Folder.READ_ONLY);
        }

        SearchTerm toTerm = new RecipientTerm(RecipientType.TO, new InternetAddress(to));
        messages = inbox.search(toTerm);

While the script is running, it executes this in a 100 iteration loop with a 3 second pause. When it's failing script output with imap debugging on repeatedly shows the following:

A4 SEARCH TO [email protected] ALL
* SEARCH
A4 OK SEARCH completed (Success)

But no actual result. during the period of execution, however, I can do a search in gmail for this recipient and it pops right up. Any suggestions for getting to the bottom of this?


Solution

  • I implemented a local cache. I initialize it at the beginning of the load test scenario, downloading the last days messages and capturing the last messages UID (using gmail imap plugin). Any time a session looks for an email it looks in the local cache. If it's not there it sets a flag so other sessions don't overlap caching and retrieves the newest messages.

    Because it was intermittent, I wanted to give it a few days. It's run perfectly for the past 4 days. I could probably go one step better and set up a listener on the folder for new mail, but for now I'm satisfied that gmail was just returning 'success' but not doing the search after so many imap searches in succession.

    Thanks to all for your feedback and suggestions!