Micro Focus QTP (UFT) Forums
Extracting Email Body from Outlook - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Extracting Email Body from Outlook (/Thread-Extracting-Email-Body-from-Outlook)



Extracting Email Body from Outlook - waseem.khan.91 - 03-01-2019

Hi All,

I've been trying to simply display the body email of an email message in a message box (code below), but consistently get a general run error and I don't know where i've been wrong.  I've even attempted to save the email but get them 'General Run Error'.  Any help would be appreciated! Thanks!

Using UFT version 14.51



Set OutlookApp = CreateObject("Outlook.Application")

Set myNamespace = OutlookApp.GetNameSpace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(6)
myFolder.Display

Set colItems = myFolder.Items
Set colFilteredItems = colItems.Restrict("[SenderEmailAddress] = 'no-reply@verificationemail.com'")

For each item in colFilteredItems

If item.Unread  Then

If InStr(item.Subject, "SKF Insight Rail") > 0 Then

'item.SaveAs "C:\Email Data\Text.txt", 0

myBody = item.body

item.unread = false


End If

End If

Next

msgbox myBody