14 July 2010

This is a really simple post about a very simple concept of sending an email using QTP. Sending emails in Software Testing is of utmost importance. You are required to send test reports and various attachments supporting the defects, tests, etc. A common scenario is when you are required to send an attachment with an email reporting the status of the end at its end. It becomes simple if you are using Quality Center with QTP as you can use the inbuilt solutions. I am trying to highlight the concept of sending an email from QTP using Microsoft's Collaboration Data Objects (CDO).

In order to achieve the goal of sending the email via QTP, we will use the methods of IMessage Interface and IConfiguration Interface of Microsoft's CDOSYS Library. You would require the SMTP server settings of the email service that you wish to use for sending the email. If you are using Gmail, the server is smtp.gmail.com (Port 25) and for hotmail, it is smtp.live.com (Port 25). In case you are using your company's SMTP server, you would require its correct SMTP details before you can get your emails delivered.

In the code above, we are creating an object of the IConfiguration Interface of CDOSYS Library and then loading all the default fields for configuring the SMTP server (by putting value as -1) using the method Load. Value of 1 loads the default values from IIS (Microsoft Internet Information Server). Value of 2 loads the values from Microsoft Outlook.

5 comments:

Its works well on system connected to public network. However in corporate network(which has proxy server settings) it doesn't work. How can we instruct the code to send this smtp request thru a specific proxy and not thru default one?

Sending an email using QTP seems very tedious. I myself had difficulty sending emails using this technique. Anyway, it's good that you have posted this simple tutorial. Many users will surely benefit from this.