QuickTest查找邮件,获取内容或标题
上一篇 /
下一篇 2010-09-26 16:15:34
/ 个人分类:QTP
以前说过,这种操作源于office的COM接口,函数参考msdn就可以了。函数返回不太好,我认为用参数返回更好,函数返回正确或错误值代码就行。51Testing软件测试网9Y/z`FGo+F
B)Ibav2se$S6n0
+^/d/o?[9V'N0Function getMailContent(strFolderWithinInbox, strSenderName, nMinuteBefore)
(C6?O:XgMG0 'nMinuteBefore, mail received time more than nMinuteBefore minutes before Now, not be a target.51Testing软件测试网
I&~3G
h"c!H/i@4\"U^u
'Create or get outlook instance.51Testing软件测试网J(E4E"h)M d
Set appOutlook = CreateObject("Outlook.Application")
6^ z
P$s"g0 Set myFolder = appOutlook.GetNamespace("MAPI").GetDefaultFolder(6)51Testing软件测试网h*p!TdC
^&{
51Testing软件测试网h%i:^!R \}
'Set your sub folder when you need, i.e. "working" in your Inbox.51Testing软件测试网;UM/UK9x/}!].w0l
If Len(strFolderWithinInbox) <> 0 Then51Testing软件测试网+_W!m,HNw}
Set myNewFolder = myFolder.Folders(strFolderWithinInbox)51Testing软件测试网f O0?UF4j*G
Set myItems = myNewFolder.Items51Testing软件测试网"e#~+h} ]&A:MO6N7k/f
Else
sr ^j#U[ b `%J0 Set myItems = myFolder.Items
@cY B9_Hm0M'R0 End If
h~NFF`Py;`051Testing软件测试网
~rO E-Nvx'~:P
Kz
'If no letter found, exit action.51Testing软件测试网7CXf;J9OG:hJ*S+A
If myItems.count = 0 Then ExitAction(0)51Testing软件测试网xi3{)P.O4V~j9}Y
!ae:b5Ty%^a0 'Iterate the items.
b0[H&ybi)Z0 Set myItem = myItems.GetFirst
xI.tp3h8p0T5t0 Dim i, bFound, strLetterBody, strLetterSubject, mailTime51Testing软件测试网3v(ejCi.S
strLetterBody = ""51Testing软件测试网[%V wLdGZ
bFound = False
r%N#s1\3e0Rv0 Do While Typename(myItem) <> "Nothing"51Testing软件测试网\X~*~2hTO
\+z`
'oShell.Popup "Item #" & i & ":" & myItem.Subject, 2, "hello"51Testing软件测试网.F(u)bT2K'Bcm7J
If (myItem.SenderName = strSenderName) Then51Testing软件测试网 E;d{9mr4jh
mailTime = myItem.ReceivedTime
/Y4W(L[{0 If (DateDiff("n", Now, mailTime) < nMinuteBefore) Then
X
?0Y8GZn'O0 strLetterBody = myItem.Body51Testing软件测试网3L1K^"H_ \{O$z T
strLetterSubject = myItem.Subject51Testing软件测试网)~$L4C(R2B!Pk
Exit Do51Testing软件测试网 qmMpWY])`A'p
End If51Testing软件测试网"B_
{6[I6D(]Sk
End If51Testing软件测试网Pe"J5J^f? |7EW
Set myItem = myItems.GetNext
#hrh/Y D0 Loop51Testing软件测试网~9T/Jw,TV4MiT
o9p.A:t.@RW/_8U(y0 getMailContent = strLetterBody51Testing软件测试网1j4\rS)Tz
51Testing软件测试网['Xw
zIHcg
'Clear resource.
C/_T%^P8G0 Set itm = Nothing51Testing软件测试网5o'@)p3C Unq
Set myFolder = Nothing
~?^H n
z:U{`H0 Set appOutlook = Nothing51Testing软件测试网Z0cHl"r'N,@;b0`j
Set Shell = Nothing51Testing软件测试网:gc9Y|AlF%`
End Function
收藏
举报
TAG: