使用QTP查找邮件

参考:

http://www.51testing.com/?uid-173503-action-viewspace-itemid-201647

 

 

Function getMailContent(strFolderWithinInbox, strSenderName, nMinuteBefore)
    'nMinuteBefore, mail received time more than nMinuteBefore minutes before Now, not be a target.
    'Create or get outlook instance.
    Set appOutlook = CreateObject("Outlook.Application")
    Set myFolder = appOutlook.GetNamespace("MAPI").GetDefaultFolder(6)

    'Set your sub folder when you need, i.e. "working" in your Inbox.
    If Len(strFolderWithinInbox) <> 0 Then
        Set myNewFolder = myFolder.Folders(strFolderWithinInbox)
        Set myItems = myNewFolder.Items
    Else
        Set myItems = myFolder.Items
    End If

    'If no letter found, exit action.
    If myItems.count = 0 Then ExitAction(0)

    'Iterate the items.
    Set myItem = myItems.GetFirst
    Dim i, bFound, strLetterBody, strLetterSubject, mailTime
    strLetterBody = ""
    bFound = False
    Do While Typename(myItem) <> "Nothing"
        'oShell.Popup "Item #" & i & ":" & myItem.Subject, 2, "hello"
        If (myItem.SenderName = strSenderName) Then
            mailTime = myItem.ReceivedTime
            If (DateDiff("n", Now, mailTime) < nMinuteBefore) Then
                strLetterBody = myItem.Body
                strLetterSubject = myItem.Subject
                Exit Do
            End If
        End If
        Set myItem = myItems.GetNext
    Loop

    getMailContent = strLetterBody

'Clear resource.
    Set itm = Nothing
    Set myFolder = Nothing
    Set appOutlook = Nothing
    Set Shell = Nothing
End Function

 

 

posted on 2011-01-12 20:18  TIB  阅读(407)  评论(0编辑  收藏  举报

导航