Team Fly |
Page 109
One quick way to add an e-mail-reading feature to a VB.NET application is to employ the facilities in Outlook.
First, use VB.NET's Project Add Reference dialog box to add a reference to the COM library named Microsoft Outlook 10.0 Object Library. (Your version might not be 10.0.)
The Outlook object hierarchy exposes several ''folder" objects: olFolderCalendar, olFolderContacts, olFolderDeletedItems, olFolderDrafts, olFolderInbox, olFolderJournal, olFolderNotes, olFolderOutbox, olFolderSentMail, olFolderTask. If you've worked with Outlook, you'll notice that these folders correspond to the various utilities and features available within Outlook.
To access the Outlook folders, you have to instantiate them indirectly by creating a MAPI message store (like API, only with the term messaging prepended).
Don't bother yourself with the wearisome nonsense that "explains" why you must first create a special Outlook namespace, then get a MAPI store. You'll add nothing to your understanding of programming by trying to follow the reasoning for this unique way of accessing Outlook's object library. Only Outlook does things this freaky way, so no use learning a process that occurs only once. You wouldn't study mammalian behavior by examining a platypus. Just copy the code in the examples below and you're home free.
WARNING Before you can test this example code, you must ensure that there's at least one e-mail message in your Outlook Inbox. Otherwise, the code will fail—I'm not bothering here to employ a Try...Catch...End Try failsafe error-trapping structure.
Put a TextBox, ListBox, and button on a form, then type Listing 4.13 into the Button's Click event.
LISTING 4.13: GETTING INBOX E-MAIL MESSAGES |
Private Sub Button1_Click(ByVal sender As System.Object, _ |
Team Fly |