How to send Emails with Jmeter (SMTP Sampler)
Today we will learn
———————————————————————————————————
1. How to load test email server
2. Configure SMTP sampler to send email
________________________________________________________________________________
Step 1 : Configuring JavaMail
The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications. The JavaMail API is available as an optional package for use with the Java SE platform and is also included in the Java EE platform.
- Download JavaMail(javax.mail.jar) from here.
- Put the jar file in lib folder of JMeter.
![](/storage/images/2019-09-24/img_92jvI_0.18592100 1569339177.png)
Step 2 :Create Test Plan & Add Thread Group
- I have already posted a tutorial on how to add Thread group to a Test Plan. Click here to check.(Upto step-3)
Step 3 : Add SMTP sampler
The SMTP Sampler can send mail messages using SMTP/SMTPS protocol. It is possible to set security protocols for the connection (SSL and TLS), as well as user authentication. If a security protocol is used a verification on the server certificate will occur.
To add SMTP sampler [Thread Group->Add->Sampler->SMTP sampler]
- Server : Hostname or IP address of the server. See below for use with file protocol. For gmail the servers will be smtp.googlemail.com / smtp.gmail.com
- Port : Port to be used to connect to the server. Defaults are: SMTP=25, SSL=465, StartTLS=587
- Connection timeout : Connection timeout value in milliseconds (socket level). Default is infinite timeout.
- Read timeout : Read timeout value in milliseconds (socket level). Default is infinite timeout.
![](/storage/images/2019-09-24/img_uWjMf_0.14380400 1569340431.png)
- Address From : The from address that will appear in the e-mail
- Address To : The destination e-mail address (multiple values separated by ";")
![](/storage/images/2019-09-24/img_Nn9rf_0.79462300 1569340535.png)
- Use Auth : Indicates if the SMTP server requires user authentication.(Sender's email id & password)
![](/storage/images/2019-09-24/img_74JRo_0.28064900 1569340579.png)
- Use no security features : Indicates that the connection to the SMTP server does not use any security protocol.
- Use SSL : Indicates that the connection to the SMTP server must use the SSL protocol.
- Use StartTLS : Indicates that the connection to the SMTP server should attempt to start the TLS protocol.
- Enforce StartTLS : If the server does not start the TLS protocol the connection will be terminated.
![](/storage/images/2019-09-24/img_ColAJ_0.77665200 1569340675.png)
Finally the message subject & message body
![](/storage/images/2019-09-24/img_JqUhf_0.42345300 1569340787.png)
We can also attach files with the message.
Step 4 : Add Listener to validate the test
Just add a simple listener Results Tree to check the result [Thread Group->Add->Listener->View Results Tree] & run the test.
![](/storage/images/2019-09-24/img_eZdZ7_0.04993100 1569341333.png)
This is the actual validation that we were expecting,
![](/storage/images/2019-09-24/img_MxdeV_0.04701800 1569341609.jpg)
There might be 99% chance of getting an error code 500 & a failed test because Google doesn't allow less secure apps to access authenticated user details.
![](/storage/images/2019-09-24/img_6zu9C_0.32888500 1569342948.png)
To avoid this, either use a test mail id provided by the organization or go to Google account settings->Security->Allow access to less secure apps to allow JMeter to access to your account.
This is all about the article. Hope you will find it useful.