Microsoft Knowledge Base |
|
HOWTO: Writing an Active Messaging Inbox Agent in Visual Basic |
|
|
Last reviewed: July 18, 1997
Article ID: Q171425 |
|
The information in this article applies to:
SUMMARYThis code sample demonstrates how to use Active Messaging to find out how many new, unread messages have been delivered to your Inbox since the last time this code was run. While this task may be trivial, this code sample demonstrates the following Active Messaging tasks in Visual Basic:
For more information about starting an Active Messaging session using the current user's default profile, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q171422 TITLE : HOWTO: Logging on to Active Messaging Session with Default Profile MORE INFORMATIONThis code requires a reference to the "Microsoft Active Messaging 1.1 Object Library" (Olemsg32.dll). Copy the following code to a module:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Public objSession as MAPI.SessionCopy the following code to the general declaration section of a form:
Private Sub Form_Load()
Set objSession = CreateObject("MAPI.Session")
'Try to logon. This line of code will log you onto the current
'session. If this fails, the most likely reason is that you do not
'have an open session.
'The error -2147221231 MAPI_E_LOGON_FAILED will return.
objSession.Logon ShowDialog:=False, NewSession:=False
FindNewMessages
End Sub
Sub FindNewMessages()
Dim objInbox As Folder 'Inbox
Dim objMessages As Messages 'Messages collection
Dim objOneMessage As Message 'One message from the message
'collection
Dim objMsgFilter As MessageFilter 'Message Filter set to
'Unread=True
Static dteLastItemReceived As Date 'Used to store the TimeReceived
'property of the last message in
'the inbox
Dim i As Integer 'Loop counter
Dim iNewMessages As Integer 'Counter for how many new
'messages there are
iNewMessages = 0
Set objInbox = objSession.Inbox 'Set the inbox object
Set objMessages = objInbox.Messages 'Set the messages object
Set objMsgFilter = objMessages.Filter 'Set the Message Filter object
objMsgFilter.Unread = True 'Set the filter's "Unread"
'property to true (look for
'unread messages only).
'Loop through all of the unread messages. Get each item in
'turn and determine if it's "TimeReceived" property is
'greater than the "TimeReceived" stored in your static
'variable "dteLastItemReceived". If it is, this is a
'new message and increment the counter.
For i = 1 To objMessages.Count
Set objOneMessage = objMessages.Item(i)
If objOneMessage.TimeReceived > dteLastItemReceived Then
iNewMessages = iNewMessages + 1
End If
Next i
MsgBox "There are " & iNewMessages & " new unread messages " & _
"since the last time I checked"
'Reset dteLastTimeSent to the TimeSent of the last message
dteLastItemReceived = objOneMessage.TimeReceived
End Sub
|
|
Keywords : ActMsg
©1997 Microsoft Corporation. All rights reserved. Legal Notices. |