Warm tip: This article is reproduced from serverfault.com, please click

How to read latest email in Gmail using Jmeter?

发布于 2020-12-04 02:37:51

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?

I've attached the screenshot of my configuration. enter image description here

Questioner
kishor sharma
Viewed
0
Dmitri T 2020-12-04 19:17:50

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: