DOCUMENT:Q185171 08-MAY-1998 [vbwin] TITLE :HOWTO: How to Use MAPI with Visual Basic 5.0 PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0 OPER/SYS:WINDOWS KEYWORDS:kbnokeyword ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 5.0 --------------------------------------------------------------------- SUMMARY ======= This article shows how to create a simple MAPI client program. The article also demonstrates how to display existing messages and how to create and send new messages. MORE INFORMATION ================ Through the use of MAPI controls in Visual Basic 5.0, it is relatively easy to create a MAPI Client. The following instructions and code show you how: 1. Start up Visual Basic 5.0 and select a Standard EXE project. On the Project menu, click Components, and select Microsoft MAPI Controls. There are two new icons displayed on the toolbar. Both icons have envelopes; one with a key, the other with a paperclip. These are your MAPI controls. 2. Add these MAPI controls to your form. 3. Add the following items to the form: Four Labels Four CommandButtons Four TextBoxes The label captions are as follows: Label1.Caption = "To:" Label2.Caption = "SUBJECT:" Label3.Caption = "FROM:" Label4.Caption = "MESSAGE:" 4. Place the TextBoxes in numerical sequence with these labels (side-by- side for labels 1 thru 3, and below for label 4). 5. Label the CommandButtons as follows: Command1.Caption = "<<" Command2.Caption = ">>" Command3.Caption = "Connect" Command4.Caption = "Send" Command5.Caption = "Close Session" 6. Add the following code to your form: Option Explicit Dim X As Long Private Sub Command1_Click() If X - 1 < 0 Then Else X = X - 1 MAPIMessages1.MsgIndex = X Text1.Text = MAPIMessages1.RecipDisplayName Text2.Text = MAPIMessages1.MsgSubject Text3.Text = MAPIMessages1.MsgOrigDisplayName Text4.Text = MAPIMessages1.MsgNoteText End If End Sub Private Sub Command2_Click() If X + 1 > MAPIMessages1.MsgCount Then X = MAPIMessages1.MsgCount Else X = X + 1 MAPIMessages1.MsgIndex = X Text1.Text = MAPIMessages1.RecipDisplayName Text2.Text = MAPIMessages1.MsgSubject Text3.Text = MAPIMessages1.MsgOrigDisplayName Text4.Text = MAPIMessages1.MsgNoteText End If End Sub Private Sub Command3_Click() MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.Fetch If MAPIMessages1.MsgCount > 0 Then Text1.Text = MAPIMessages1.RecipDisplayName Text2.Text = MAPIMessages1.MsgSubject Text3.Text = MAPIMessages1.MsgOrigDisplayName Text4.Text = MAPIMessages1.MsgNoteText Command4.Enabled = True Else MsgBox "No messages to fetch" MAPISession1.SignOff Command4.Enabled = False End If End Sub Private Sub Command4_Click() MAPIMessages1.Compose MAPIMessages1.RecipDisplayName = Text1.Text MAPIMessages1.MsgSubject = Text2.Text MAPIMessages1.MsgNoteText = Text4.Text MAPIMessages1.ResolveName MAPIMessages1.Send End Sub Private Sub Command5_Click() MAPISession1.SignOff Unload Me End Sub Additional query words: kbDSupport kbdse kbvbp500 ====================================================================== Keywords : kbnokeyword Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.