Micro Focus QTP (UFT) Forums
QTP:How to find an email with a subject line in MS outlook and then click on an link - 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: QTP:How to find an email with a subject line in MS outlook and then click on an link (/Thread-QTP-How-to-find-an-email-with-a-subject-line-in-MS-outlook-and-then-click-on-an-link)



QTP:How to find an email with a subject line in MS outlook and then click on an link - royrover - 08-18-2010

Hey guys

I am trying to solve this problem using QTP where i need to make sure that an email is generated every time i do a successful registration on my product

So the business life cycle is something like this
1. Register on the product
2. An email is generated which i am sending to outlook

Expected result
1. An email is generated on a successful registration ( This email is in a sub folder of my inbox like Notifications_test)
2. If possible do any further validation on the To address field and the body of the email with the template it is supposed to send

Can somebody help?

Till now i have

Code:
Set olapp = createobject("outlook.application")
set inbox = olapp.getnamespace("mapi").folders

for each fold in inbox
msgbox fold.name
getsubfolders(fold)
next

msgbox Notifications_Test.count
sub getunreadmails(objfolder)
'sub getunreadmails(Notifications_Test)
set col = objfolder.items

for each mail in col

If mail.subject = "[IUSR] Validation Instructions[x@y.com]" then

msgbox mail.subject
msgbox mail.sendername
msgbox mail.body
msgbox mail.senton

end if

next

end sub

I will appreciate any help


RE: QTP:How to find an email with a subject line in MS outlook and then click on an link - Arun Prakash - 08-18-2010

Create a folder for that particular Type of mail
and check in that folder
Code:
Option Explicit

    Dim dicEmailAddresses
    Dim strLogFolder
    Dim strEmail

    strLogFolder = "C:Program FilesSpare BackupLogs"
    Set dicEmailAddresses = GetEmailAddressesFromLogs(strLogFolder)

    For Each strEmail In dicEmailAddresses.Keys()
        WScript.Echo strEmail
    Next

    Function GetEmailAddressesFromLogs(StrSource)
        Dim oFSO
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        Dim oFolder
        Dim strLine
        Dim dicResults
        Dim strEmail
        Dim oFile
        Set oFile = oFSO.GetFolder(strLogFolder)


        Set dicResults = CreateObject("Scripting.Dictionary")
        For Each oFile In oFSO.GetFolder(strSource).Files
            For Each strLine In Split(oFile.ReadAll(), VbCrLf)
                If InStr(strLine, "INFO: Logging in ") > 1 Then
                    strEmail = Split(strLine, "INFO: Logging in ")(1)
                    If Not dicResults.Exists(strEmail) Then
                        dicResults.Add strEmail, ""
                    End If
                End If
            Next
        Next

    Set GetEmailAddressesFromLogs = dicResults End Function
Has this answred your question?


RE: QTP:How to find an email with a subject line in MS outlook and then click on an link - royrover - 08-18-2010

Does it require no mapi object?

My intention is to integrate with microsoft outlook and check in a particular folder in the inbox and check for that validation email to show up


RE: QTP:How to find an email with a subject line in MS outlook and then click on an link - Arun Prakash - 08-19-2010

Try to use the below code.I think this will solve your problem
Code:
Set olapp = createobject("outlook.application")
set inbox = olapp.getnamespace("mapi").folders

for each fold in inbox
    msgbox fold.name
    If fold.name = "Give The main Folder name" Then
        getsubfolders(fold)
    End If
    
next

    msgbox inbox.count
    sub getunreadmails(objfolder)

        set col = objfolder.items
    
        for each mail in col
            if mail.unread then
                msgbox mail.subject
                msgbox mail.sendername
                msgbox mail.body
                msgbox mail.senton
                mail.unread=false
            end if
        next

    end sub
    sub getsubfolders(objparentfolder)
        set colfolders = objparentfolder.folders
        for each objfolder in colfolders
            set objsubfolder = objparentfolder.folders(objfolder.name)
            if objfolder.name="Give the Sub Folder Name" then
                getunreadmails(objfolder)
            end if
            getsubfolders objsubfolder
        next
    end sub