QuickTest查找邮件,获取内容或标题。

上一篇 / 下一篇  2009-12-29 10:01:15 / 个人分类:Quick test professional

以前说过,这种操作源于office的COM接口,函数参考msdn就可以了。函数返回不太好,我认为用参数返回更好,函数返回正确或错误值代码就行。


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

TAG:

cnsong99的个人空间 引用 删除 cnsong99   /   2010-01-13 09:48:48
不错
 

评分:0

我来说两句

Open Toolbar