Outlook.Application

Purpose of using Outlook.Application in QTP is

a. To send the QTP results to the respective managers after run session ends

b. In some of the applications like register a user / update / delete..etc the application will trigger a mail to inbox, in automation we can read the mail from inbox and confirm the mail is received or not after the create / update / delete transaction in application.

the API for using outlook is Outlook.Application. and you should have configured outlook in your system.

Below are some the programs using the API

'''''''Read the defaultFolder name (which is Inbox)
dim mso
set mso=CreateObject("Outlook.Application")
set msns=mso.GetNameSpace("MAPI")
set mf=msns.GetDefaultFolder(6)
msgbox mf.name

========================

''''''''Send a new mail with attachment

Set otl=CreateObject("Outlook.Application")
Set m=otl.CreateItem(0)
m.to="email@address.com"

m.cc="user1@address.com;user2@address.com;user3@address.com"
m.bcc="user6@address.com;user6@address.com"

m.Subject=Subject
m.Body=Body
m.Attachments.Add("Path of the file")


m.Send
otl.Quit
Set m = Nothing
Set otl = Nothing

==========================
'''''''''read all unread mails from Inbox

dim mso
set mso=CreateObject("Outlook.Application")
set msns=mso.GetNameSpace("MAPI")
set mf=msns.GetDefaultFolder(6)

for each ml in mf.items
  if m1.unread Then
      print m1.body
  end if
Next

=====================

Comments