How to send Emails with Jmeter (SMTP Sampler) | QAProvider.com
Subscribe me on new discussions

How to send Emails with Jmeter (SMTP Sampler)

Views: 8

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.

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.
  • Address From : The from address that will appear in the e-mail
  • Address To : The destination e-mail address (multiple values separated by ";")
  • Use Auth : Indicates if the SMTP server requires user authentication.(Sender's email id & password)
  • 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.

Finally the message subject & message body

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.

This is the actual validation that we were expecting,

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.

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.

Thank You

Karma: {{ total }}