Check for new email in OutlookTag(s): WSH VBScript


Set otl = createobject("outlook.application")
Set session = otl.getnamespace("mapi")
session.logon
Set inbox = session.getdefaultfolder(6)
c = 0
For Each m In inbox.items
  If m.unread Then c = c + 1
Next
session.logoff
s = "s"
If c = 1 Then s = ""
Msgbox "You have " & c & " unread message" & s
Alternate method
    Dim onMAPI As NameSpace
    Dim ofFolder As MAPIFolder
    Dim oItem As Object
    Dim omNewMail As MailItem

    Set oWSHShell = CreateObject("wscript.shell")

    Set onMAPI = GetNamespace("MAPI")
    Set ofFolder = onMAPI.GetDefaultFolder(olFolderInbox)
    Set omNewMail = ofFolder.Items.GetFirst

    Ret = oWSHShell.PopUp("You have new mail from " & _
              omNewMail.SenderName & _
              " about " & omNewMail.Subject & "." & vbCrLf & _
              "Would you like to read it now?", 5, _
              "You have New Mail ", 65)

    If Ret = vbYes Then
        omNewMail.Display
    End If

blog comments powered by Disqus