I have a requirement to retrieve unread mails from Gmail. I am using Java Mail API. By default, this API retrieves mails from the oldest to newest. But I need to retrieve re
JavaMail gives you an array of Message objects. The messages are in the order received. If you want to look at the most recently received messages first, go through the array in the reverse order. If you want to look at the most recently sent messages first, you'll need to sort the array, as described in the other answer.