Friday, August 21, 2009

QTP Script to read an email message.

Reading an email message

The below code goes through all the messages in an Outlook Inbox and shows all the Unread messages in message box. (I have used Outlook 2007). Write the below code in a new test in QTP and run it. Make sure Outlook is open while you run the test.

'using the CreateObject method to create an Outlook Application object.
Set olApp = CreateObject("Outlook.Application")
'GetNameSpace - Returns a NameSpace object of the specified type. It exists because outlook was designed to be usable with different kinds of data, each of which would be identified by its own namespace. So far, only one kind of data is supported in Outlook, MAPI data (Messaging Applicaiton Programming Interface).
Set olns = olApp.GetNameSpace("MAPI")
'Returns a MAPIFolder object that represents the default folder of the requested type for the current profile
Set objFolder = olns.GetDefaultFolder(6)

For each item1 in objFolder.Items
If item1.unread Then
msgbox item1.body
End If
Next


Also See:

QTP & Microsoft Outlook Object Model
QTP Script to get inbox folder name in messagebox
QTP Script to count emails in any Outlook folder
QTP Script to enumerate all folders in Outlook
QTP Script to send an email from Outlook
QTP Script to send an email with attachment from Outlook
QTP Script to download an email attachment from Outlook