Outlook search from QTP
Question ID: 104985
0
0

Is there a way in QTP to search the inbox of Outlook for a specific e-mail? Once found, is there a way to view the
attachments?

Marked as spam
Posted by (Questions: 227, Answers: 22)
Asked on April 30, 2013 3:31 pm
131 views
Answers (1)
2
Private answer

You can use Outlook`s Automation Object Model to search for e-mails and select attachments

The example code below demonstrates how to search for the first e-mail from ''test@tester.com.'' If the
e-mail has attachments, they will be saved to a local drive and then opened for viewing.

Note:
This code is not part of QuickTest Professional and is not guaranteed to work with all versions of Outlook.

Set WshShell = CreateObject(''WScript.Shell'')
Set objOutlook = CreateObject(''Outlook.Application'') ' Create an Outlook object to interact with.
Set myNameSpace = objOutlook.GetNameSpace(''MAPI'')
Set ClientFolder = myNameSpace.GetDefaultFolder(6) ' 6 is for Inbox
Set myItems = ClientFolder.Items
Set myItem = myItems.GetFirst

For i=1 to ClientFolder.Items.Count
If (myItem.SenderName = ''test@tester.com'') Then 'Check for Sender
MsgBox myItem.Subject,,''Email Subject'' 'Displays the Subject
MsgBox myItem.Body,,''Email Content'' 'Displays the Body of the mail

If myItem.Attachments.Count <> 0 Then
attachments = ''FileName'' & vbTab & vbTab & ''Type'' & vbCr & vbCr
For j = 1 To myItem.Attachments.Count
FileName = myItem.Attachments.Item(j)
FileType = Split(FileName,''.'')
attachments = attachments & FileName & vbTab & vbTab & FileType(1) & vbCr
myItem.Attachments.Item(j).SaveAsFile ''c:'' & FileName 'Saving the Attachments
WshShell.Run ''c:'' & FileName 'Opening the Attachments
Next
MsgBox attachments,,''Attachment Status'' 'Will display Attachment details
Else
MsgBox ''No Attachments with this Email'',,''Attachment Status''
End If

Exit For 'Remove this Statement, if you want to look for all matching emails.
End IF

Set myItem = myItems.GetNext

Next

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on April 30, 2013 3:32 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top