my test scenario is if I perform some action using API, then I am receiving an email.
I have used Mail Reader Sampler to read an email. I can successfully read the email. But the problem is it reads the oldest email. I want to read the latest email.
How can I read the latest email?
If you want to get the single latest message and avoid receiving all of them you will have to switch to JSR223 Sampler and do this in Groovy language, example code:
props.setProperty('mail.transport.protocol', 'imaps')
props.setProperty('mail.imap.host', 'imap.gmail.com')
props.setProperty('mail.imap.port', '995')
props.setProperty('mail.imap.ssl.enable', 'true');
def session = javax.mail.Session.getDefaultInstance(props, null)
store = session.getStore('imaps')
store.connect('imap.gmail.com', 'your-username@gmail.com', 'your-password')
inbox = store.getFolder('INBOX')
inbox.open(javax.mail.Folder.READ_ONLY)
def message = inbox.getMessage(inbox.total)
return message.getContent()
More information: