Read mails through JMeter
JMeter is a free java-based tool that can be used for monitoring.
In my case I needed to check the activation URL in a confirmation mail.
To read mails JMeter uses the Mail Reader Sampler. Before you can use this sampler you need to place the Java Mail.jar in the JMeter lib directory.
But the Mail Reader Sampler treats all the mails as subsamples, and most post processors cannot use them.
So, to get the activation URL I used a BeanShell PostProcessor. If you use BeanShell you need to place bsh-2.0b4.jar in the JMeter lib directory.
The URL I needed to check was from the following format: https://www.[domain].be/Action.do?URL=[Activation Code]"
I only needed the Activation Code. This is the BeanShell PostProcessor code I used:
import org.apache.jmeter.samplers.SampleResult;
counter = 1;
temp=null;
newVal = "INVALID";
//get all mails
results = prev.getSubResults();
for(SampleResult result: results) {
mail = result.getResponseDataAsString();
//check sender and subject
if(mail.contains("From: [Sender]") && mail.contains("Subject: [Subject]")) {
//get URL
temp = mail.split("URL=");
temp = temp[1].split(”\”>”);
newVal = temp[0];
}
//put url in JMeter variable
vars.put("activationCode", newVal);
counter++;
}
The Activation code is now in the JMeter variable: $[activationCode] which can be accessed from Samplers, Pre & Post-Processors,...
To access this variable, you need to define it in JMeters User Defined Variables first. Otherwise JMeter doesn't know about it existence.
I used a split to get the activation code out of the URL, you could also use a regex which would be something like this: .*URL=([^"]*).*
March 5th, 2010 - 18:10
Thankss very util.