WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE and Outlook
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Outlook - Get Oldest Email Message


objOutlook = ObjectCreate ("Outlook.Application")
objNs = objOutlook.GetNamespace("MAPI")
objFolderInbox  = objNs.Folders("Personal Folders").folders("Inbox")
objMailItems = objFolderInbox.Items
mailitemcount = objMailItems.Count
;Get oldest Mailitem
oldestrcvd = 0
oldestentryid = 0
For xx = 1 To mailitemcount
    objMailItem=objFolderInbox.Items( xx )
    receivedtime = objMailItem.ReceivedTime
    entryid = objMailItem.EntryId
    If xx == 1
       oldestrcvd = receivedtime
       oldestentryid = entryid
    Else
       If receivedtime < oldestrcvd
          oldestRcvd = receivedtime
          oldestEntryId = entryid
       EndIf
    EndIf
    objMailItem= 0
Next

;Get Data from oldest message
objMailItem = objNs.GetItemFromID(oldestEntryId)

receivedtime = objMailItem.ReceivedTime
subject = objMailItem.Subject
body = objMailItem.Body
Message( "Oldest Message", "[ReceivedTime]: ":receivedtime:@CRLF:"[Subject]: ":subject:@CRLF:@CRLF:"[Body]: ":body)

;Clean up
objMailItem = 0
objMailItems = 0
objFolderInbox = 0
objNs = 0
objOutlook = 0
Exit

Article ID:   W17129
File Created: 2007:07:03:14:28:26
Last Updated: 2007:07:03:14:28:26