JMeter is an open-source tool that helps to perform load testing. It provides various samplers to perform load testing. Today, we will discuss email related samplers. There are two samplers to perform an action related to the email, read(mail reader sampler) and send(SMTP) email. With the help of these samplers, we can execute email related test cases in load testing activities.
Steps to read emails:
- Initially, Configure the Javamail in the JMeter.
Download JavaMail(javax.mail.jar) from this link:
Put the JavaMail jar into the JMeter ‘lib folder’ and restart it.
Location to add file : C:\apache-jmeter-5.4\lib
- Create a Test plan and Add a Thread Group.
- Add mail reader sampler:
Thread Group->Add->Sampler->mail reader sampler
- Once the mail reader sampler added, we need to add data into it:
- Here, we need the Gmail protocol to read the email from Gmail in JMeter. To get email protocol, access this link Gmail Protocol. We will use the Gmail IMAP protocol for receiving an email in JMeter. Therefore, set the Protocol value to ‘imaps’. Similarly, enter ‘imap.googlemail.com’ and ‘993’ as ‘server host’ and ‘port’ values respectively.
- Enter a valid username(email address) and password.
- Specify the number of emails.
- Select “Use SSL” from the ‘security setting’ as Gmail requires an SSL certificate.
Other options available in the mail reader sampler:
Folder: A folder in an email account.
Delete messages from the server: Specify whether JMeter should remove messages from the server after retrieval.
Store the message using MIME: Specify whether the entire message will be stored in the Response Data.
- Finally, Add a listener to see the result and Run the script. Here, we are using the ‘Result tree’ listener.
Thread Group->Add->Listener->View Results Tree
Configuration setting in Gmail account to access in the JMeter:
To access Gmail in the JMeter, we need to do some configuration settings in the Gmail account. Without these changes, It throws authentication errors every time.
- Enable the IMAP from the Gmail account.
- Turn on less secure app access.
Security-> less secure app access