Sending Email With MAPI Components in Visual Basic
MAPI is an acronym for the Messaging Application Programming Interface. It's a set of core system components that can be used to automate several windows tasks. MAPI components allow developers to create mail-enabled Visual Basic applications easily. In this article Jason shows us how to use MAPI controls to read messages from our inbox, iterate through these messages, and more.
Sending Email With MAPI Components in Visual Basic - Using MAPI Components (Page 2 of 4 )
Using the MAPI controls involves two steps: firstly establishing a MAPI session, and secondly using various MAPI properties and methods to access and manage an individual inbox; for example, to create and send a message, include a file attachment, verify the recipient's email address against the email system's address book, etc.
Let's get started on the Visual Basic project, shall we? Start by creating a new standard executable application. You will need to add the MAPI components to your project, so start by clicking project from the top menu and find the menu item components (you may also use the hotkey CTRL+T). When the components window appears, scroll down the list until you find the Microsoft MAPI controls:
Place a check in the box next to it, and then click the OK button. Two additional controls have been added to the Visual Basic toolbox; they're called MAPISession and MAPIMessages. We will be using both of these in our application.
Setting up the form
Let's setup the layout of our Visual Basic application. Our form will contain four textboxes, three labels, four command buttons, and both of the MAPI components. You should layout the controls on your form so that it looks like this (alternatively, you can see the support material for this article and download the complete project):
Here are the details of each component on our Visual Basic form: