首页 > 其他 > 详细

【VBS】检索Outlook本地邮箱

时间:2015-07-14 17:51:34      阅读:228      评论:0      收藏:0      [点我收藏+]

实现功能:使用VBS检索Outlook本地邮箱中,今天是否收到某标题的邮件。

代码如下:

Const C_DATE_FORMAT_MAIL_FILTER_FROM = 1         yyyy-m-d 0:00 AM
Const C_DATE_FORMAT_MAIL_FILTER_TO = 2           yyyy-m-d 11:59 PM

Function CheckMail(pMailFolder, pMailTitle)
    On Error Resume Next
    Dim objOlApp
    Dim objNameSpace
    Dim objFolder
    Dim strFilter

    CheckMail = False
    Set objOlApp = CreateObject("Outlook.Application")
    Set objNameSpace = objOlApp.GetNamespace("MAPI")
    olFolderInbox  6  默认收件箱
    Set objFolder = objNameSpace.GetDefaultFolder(6).Folders(pMailFolder)

    If Err.Number <> 0 Then
        AddLog ("邮件访问出错:" & Err.Description)
        WScript.Quit -1
    End If

    过滤条件
    strFilter = "[Subject] = ‘" & pMailTitle _
        & "‘ And [ReceivedTime] >= ‘" & FormatDate(Now(), C_DATE_FORMAT_MAIL_FILTER_FROM) _
        & "‘ And [ReceivedTime] <= ‘" & FormatDate(Now(), C_DATE_FORMAT_MAIL_FILTER_TO) & ""

    检索
    If objFolder.Items.Restrict(strFilter).Count > 0 Then
        CheckMail = True
    End If
End Function

日期格式化
Function FormatDate(pDate, pFlag)
    Dim y, m, d
    FormatDate = ""
    If IsDate(pDate) = False Then Exit Function
    y = cstr(year(pDate))
    m = cstr(month(pDate))
    d = cstr(day(pDate))

    Select Case pFlag
        Case C_DATE_FORMAT_MAIL_FILTER_FROM
             yyyy-m-d 0:00 AM From
            FormatDate = y & "-" & m & "-" & d & " 0:00 AM"
        Case C_DATE_FORMAT_MAIL_FILTER_TO
             yyyy-m-d 11:59 PM To
            FormatDate = y & "-" & m & "-" & d & " 11:59 PM"
    End Select
End Function

 

【VBS】检索Outlook本地邮箱

原文:http://www.cnblogs.com/Ryukaka/p/4645902.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!