QuickTest Pro sample code – sending an email using Outlook
This QuickTest Pro code sample shows how you can create a subroutine that will send an email using Microsoft Outlook. The subroutine is defined and can either be placed at the top of your script (must be executed first before it is called in order for the script to know about the subroutine) or it can be placed in a Function Library and associated with the test script.
The reason to use a subroutine is to isolate the process code that creates and sends the Outlook email to a common subroutine in order to take advantage of reuse. This way every time a test script needs to send an email it just needs to have the bottom three lines of code shown below in the code image (lines 35 – 37). It utilizes the “CreateObject” to create an instance of the Outlook application in order to create the actual email. The data used in the email is passed into the subroutine using an array and then each element is referenced within the subroutine code.
![]() |
Here is the result of sending the email, the email was received and it looks like this:
![]() |
This is kind of a neat feature that you may find a need for.
In addition to the images above, here is a snippet of the code for easier readability and the ability to copy the code for your own use:
Dim objOutl, objMailMsg, objNameSpace, intRecipientCounter, strEmailAddressConst olMailItem = 0 ’ Constants for new itemsConst olAppointmentItem = 1 Const olContactItem = 2 Const olTaskItem = 3 Const olJournalItem = 4 Const olNoteItem = 5 Const olPostItem = 6intRecipientCounter=1 ’Start the email address counter at 1Set objOutl=CreateObject (“Outlook.Application”) ’Create an Outlook object Set objMailMsg=objOutl.CreateItem(olMailItem) ’Create a new Outlook mail object objMailMsg.Recipients.Add(emailInfo(0)) ’Add the email address to the recipient list of the message objMailMsg.Subject=emailInfo(1) ’Set the subject of the message objMailMsg.Body=emailInfo(2) ’Set the body of the mail message objMailMsg.Send ’Send the mail message‘Free up the memory Set objOutl=Nothing Set objMailMsg=NothingEnd Sub‘Script code to actually call the subroutine with data to be used in the email that will be sent Dim emailInfo emailInfo = Array(“test@hotmail.com”,”Subject: QTP Test email”,”Desc: This is a test email sent by QTP”) CreateEmail (emailInfo) |
Good Luck.

Category: 

Tags: 
Send email with out MS outlook.
Attaching the link.
http://bharath-marrivada.blogspot.com/2010/02/how-to-send-email-with-attachments.html
It was an absolute pleasure to read through your piece with all the interesting topics you write about. My imagination went wild with all the detailed words you used. Please carry on to grace us with your work as it is really enjoyed.
That was a really interesting post, I enjoyed reading it. You are dead right!