Working with Outlook API using UFT? – User friendly Tech help
Principle:-n
Outlook object model |
n
The above mind map structure represents the flow of objects that we have used to work with outlook API model.
n
nApplication object:–
nIt is the parent object which represents the entire Microsoft Outlook application.
nWhen 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.
n
nYou can read the complete outlook object model, to learn more.
nSyntax:-
nSet objOutlook= CreateObject(“Outlook.Application”)
n
nNamespace object:–
nThis 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.
n
nWe have used GetNamespace (“MAPI”) method, to return the Outlook Namespace object from the Application object (objOutlook in our case).
n
nSyntax:-Set OutlookSetNameSpace = objOutlook.GetNamespace(Cstr(UCase(sNameSpace)))Note: – The only supported name space type is “MAPI” in Outlook
nMAPI: – 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.
n
Folder object: –
nWe 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.
n
nSyntax:-
nSet OutlookSetFolder = objNamespace.GetDefaultFolder(sFolder)
n
nProperties of Email: – Further we have accessed the Subject,To,CC,Body,… properties to fetch the required values.
n
Code:-
n
Driver code,
n
'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 objectOutlookCloseConnection(objOutlook)
n
Function for Outlook,
n
n1.Creating and Destroying Outlook object
n
Creating/Destroying Outlook Object |
n
2.Referring the Outlook Namespace
n
Outlook Namespace |
n3.Pointing Outlook object to work with Inbox Foldern
Referring the Folder in Outlook |
n4.Finding the match for given value of the Emailn
Verify the Email |
n
5.Setting the Read/Unread Filter
n
Set filter on Outlook Emails |
n
More Practical Scenarios