Recent Post

QTP – Outlook Application


QTP – Outlook Application

Aim: To send out a mail soon after the QTP – Automation test ends.
ü  Copy this code, use it in a notepad or any text editors
ü  Save as oMail.vbs.
ü  Before adding this, make sure, you have added sufficient information to SendTo, Subject, Body contents and so.
ü  Add this file to your framework / multi test manager scripts as the last script
ü  It runs as part of your scripts (at the end) and sends out a mail to the loop of the email ids that are added to SendTo with the Subject, Body contents that are specified.

'#############################################################
'@        QTP – Outlook Application
'#############################################################

Dim SendTo, Subject, Body, Attachment
SendTo=" QuickTestQTP@gmail.com"
Subject="QuickTest QTP Info"
Body=" Here are the Automation Test Results; Thanks, G A Reddy"

Call SendMail(SendTo, Subject, Body, Attachment)

'##############################################################
'@Function   :  SendMail
'@Purpose    :  To send a mail with QTP - Automation Test Status
'@Input Paramters: SendTo, Subject, Body, Attachment
'@Output Paramters: None.
'###############################################################

Function SendMail(SendTo, Subject, Body, Attachment)
Set oOutlook=CreateObject("Outlook.Application")  
‘Outlook object is created
Set oMail=oOutlook.CreateItem(0)
oMail.To=SendTo        ‘ Added SendTo address to oMail Obj
oMail.Subject=Subject        ‘ Added Subject to oMail Obj
oMail.Body=Body        ‘ Added Body Contents to oMail Obj
If (Attachment <> "") Then    
oMail.Attachments.Add(Attachment)
‘ Checks if there are any attachments
End If
oMail.Send      ‘ Sending out mail here
oOutlook.Quit            
‘ comment this if you want your outlook not to be closed
Set oMail = Nothing
Set oOutlook = Nothing
End Function

There is also another method using CDO (Collaboration Data Objects)
Make sure that you have installed the CDONTS in your OS before running this script

Info on CDONTS:
CDONTS stands for 'Collaboration Data Objects for Windows NT Server' and as the name suggest it is for NT, sorry Win9x users you don't have this component. The CDONTS component is installed when you install IIS on NT4 and Windows 2000. Although the component will run on Windows XP, Microsoft have decided to remove the component from IIS 5.1 on Windows XP, so you will have to track down a copy of the cdonts.dll and register it on the IIS web server

To use this component to send e-mail you also need the SMTP Server that ships with IIS 4 or 5 installed on the web server. The SMTP server is usually installed by default with the standard IIS installation.

'#############################################################
'@Function   :  SendMail
'@Purpose    :  To send a mail with QTP - Automation Test Status
'@Input Paramters: SendFrom, SendTo, Subject, Body, Attachment
'@Output Paramters: None.
'##############################################################

Function SendMail(SendFrom, SendTo, Subject, Body)
Set oMail=CreateObject("CDONTS.Newmail")
oMail.From = SendFrom
oMail.To = SendTo
oMail.Subject = Subject
oMail.Body = Body
oMail.Send
Set objMail = Nothing
End Function

If you are unable to install this CDONTS the try with CDO

'###########################################################
'@Function : SendMail1
'@Purpose : To send a mail with QTP - Automation Test Status
'@Input Paramters:  SendFrom, SendTo, Subject, Body, Attachment
'@Output Paramters: None.
'#############################################################

Function SendMail1(SendFrom, SendTo, Subject, Body)
Set ObjMail=CreateObject("CDO.Message")
ObjMail.From = SendFrom
ObjMail.To = SendTo
ObjMail.Subject = Subject
ObjMail.TextBody = Body
ObjMail.Send
set objMail = Nothing
End Function

0 comments:

Post a Comment

GAReddy @ OneTestingCenter @ All Articles