Knowing how to read your e-mail from Microsoft Office Outlook using Microsoft Visual Basic can help you to develop powerful e-mail applications. Outlook is an e-mail management system that is included in the Microsoft Office suite. Visual Basic is an object-oriented computer programming language that is often preferred by programmers for its flexibility and ease of use. In a few steps you can create a Visual Basic Windows application that will read your Outlook inbox and display e-mail content through the console window.
- Skill level:
Other People Are Reading
Things you need
- Microsoft Visual Basic.NET
Open Microsoft Visual Basic Express and click "New Project..." in the left pane of the screen. Double-click "Console Application." Press "Ctrl" and "A" and then press "Delete" to remove the code that is there.
Copy and paste the following code to your "Module1.vb" module to read the email items in your Outlook inbox:
Module Module 1
Sub Main() Dim otkApp As Outlook.Application = New Outlook.Application Dim otkMailItem = "IPM.Note" Dim otkNameSpace As Outlook.NameSpace = otkApp.GetNamespace("MAPI") Dim otkInboxFolder As Outlook.MAPIFolder = otkNameSpace.GetDefaultFolder _ (Outlook.OlDefaultFolders.olFolderInbox) Dim otkMailItems As Outlook.Items = otkInboxFolder.Items Dim otkMessage As Outlook.MailItem Dim iCntr As Integer For iCntr = 1 To otkMailItems.Count If otkMailItems.Item(iCntr).MessageClass = otkMailItem Then otkMessage = otkMailItems.Item(iCntr) Console.WriteLine(iCntr) Console.WriteLine(otkMessage.SenderName) Console.WriteLine(otkMessage.Subject) Console.WriteLine(otkMessage.ReceivedTime) Console.WriteLine(otkMessage.Body) Console.WriteLine("______________________________") End If Next otkApp = Nothing otkNameSpace = Nothing otkMailItems = Nothing otkMessage = Nothing End Sub
Press "F5" to run your program.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for