Working with Outlook API using UFT?

Principle:-

Outlook object model in UFT
Outlook object model 

The above mind map structure represents the flow of objects that we have used to work with outlook API model.

Application object:
It is the parent object which represents the entire Microsoft Outlook application.
When we use Automation to control Microsoft Outlook from another application (UFT in our case), we use the CreateObject method to create an Outlook Application object.

You can read the complete outlook object model, to learn more.
Syntax:-
Set objOutlook= CreateObject(“Outlook.Application”)

Namespace object:
This object provides methods for logging in and out, accessing storage objects directly by ID, accessing certain special default folders directly, and accessing data sources owned by other users in outlook Application.

We have used GetNamespace (“MAPI”) method, to return the Outlook Namespace object from the Application object (objOutlook in our case).

Syntax:-Set OutlookSetNameSpace = objOutlook.GetNamespace(Cstr(UCase(sNameSpace)))Note: – The only supported name space type is “MAPI” in Outlook
MAPI: – The Messaging Application Programming Interface (MAPI) is a proprietary email protocol of Microsoft, that is used by Outlook (Microsoft’s email client software) to communicate with Microsoft Exchange (its email server software). Thus MAPI provides the messaging architecture for Microsoft Outlook, it provides a set of interfaces, functions, and other data types to facilitate working with outlook.

Folder object:
We have used GetDefaultFolder(FolderType) method which Returns a Folder object that represents the default folder of the requested type.In our case FolderType = 6 , which refers the inbox folder. 

Syntax:-
Set OutlookSetFolder = objNamespace.GetDefaultFolder(sFolder)

Properties of Email: – Further we have accessed the Subject,To,CC,Body,… properties to fetch the required values.

Code:-

Driver code,

'Creating the outlook Objects
Dim objOutlook,objNameSpace,objInbox,objEmail
'Opening the outlook connection
set objOutlook = OutlookOpenConnection()
'Creating the Namespace Mapi
Set objNameSpace = OutlookSetNameSpace(objOutlook, "MAPI")
'Referring to Inbox folder (VALUE = 6 , means Inbox folder)
Set objInbox=OutlookSetFolder(objNameSpace,6)
'Reading the email and doing the required comparisons
if OutlookCheckUnreadEmails("Subject", "TestMail",3) then
Print "Run is Successfull"
Else
Print "Run is Unsuccessfull"
End if
'Destroying the Outlook object
OutlookCloseConnection(objOutlook)

Function for Outlook,

1.Creating and Destroying Outlook object

Outlook object creation in Automation
Creating/Destroying Outlook Object

2.Referring the Outlook Namespace

Outlook NameSpace MAPI in UFT
Outlook Namespace
3.Pointing Outlook object to work with Inbox Folder

GetDefaultFolder method of Outlook
Referring the Folder in Outlook
4.Finding the match for given value of the Email

Outlook email verification in UFT
Verify the Email 


5.Setting the Read/Unread Filter 

Setting Filter in Outlook in UFT
Set filter on Outlook Emails

More Practical Scenarios

3 thoughts on “Working with Outlook API using UFT?

  1. Hi can you help me to get logged in email id for outlook,lets say i already configured my outlook account and its up and running now if i want to read my email id by using automation script,is there any way to get login information

Leave a Reply

Your email address will not be published. Required fields are marked *