I was browsing LinkedIn Groups this morning and I came across a discussion in the HP LoadRunner Software group. One of the testers who is a member of this group was asking whether it is possible to send an email from LoadRunner.
He had a couple of ideas about how to do this using LoadRunner’s support for either MAPI or SMTP protocols. Several contributors had suggested alternative ideas.
These suggestions included:
- Recording a web script and sending the script through a web-based mail client such as Outlook or Gmail.
- Using a third party API such as Twilio which uses REST APIs to send emails or text messages (although this incurs a cost).
- Calling MS Exchange web service APIs from in a script.
My preferred solution
Each of the above solutions has its merits but if a SMTP server is available, I've found that BLAT is a great command line utility that allows you to do this in just a few lines in your LoadRunner script. I’ve used BLAT to send emails from within LoadRunner scripts before and I blogged about it in 2010. This technique has several advantages in that you don’t need to use any proprietary protocols such as MAPI or SMTP (which you may not be licensed to use). The script is lightweight and doesn’t rely on any third party webmail services or API. All you need is an SMTP server.
Assuming that the blat.exe and blat.dll files are saved inside your script folder, the following syntax can send an email indicating that a test has completed.
char cCommand; // char variable to hold the contents of DOS commands
I’ve used this to notify DBAs or sys admins when a test completes so that they can roll back the test system to a “pre-test” state, but you could use it to email information about a performance test or send log files out via email at any time during a performance test. If you want to send the results file “Test.txt” as an attachment, rather than sending the contents of the file in the email body, you can use the –attach switch to achieve this.
The sample LoadRunner script which contains the BLAT executables as well as sample syntax for sending an email notification can be downloaded from my GitHub repository.