Microsoft KB Archive/135755

= HOWTO: Use the OLE MAPI Control to Send Mail Messages =

Article ID: 135755

Article Last Modified on 3/14/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q135755



SUMMARY
The Professional Edition of Microsoft Visual FoxPro for Windows includes a MAPI OLE container control, so the developer can incorporate mail messaging capabilities into a Visual FoxPro application. This article gives the steps necessary to create a Visual FoxPro form that starts a MAPI session and allows a user to send a mail message to a specified e-mail address.

NOTE: The MAPI OLE container controls are not installed on operating systems that use the Win32s subsystem (Windows 3.x and Windows for Workgroups 3.x).



Step-by-Step Procedure
Follow these steps to create a form to send mail messages using the OLE MAPI control.

 Create a new form. Add the OLE MAPI Session control to the form. Select the OLE Container control from the Form Controls toolbar, and then click the form. Select the Insert Control option, and select the MAPI Session control. Change the Name property of the control to OLEMAPISession. Repeat step 2, this time adding the OLE MAPI Message control to the form and changing the Name property to OLEMAPIMsg. NOTE: The location of these controls is not important, as they will not appear at run-time.  In the form's Init event procedure, add this code: This.OLEMAPISession.SignOn  Add two text boxes to the form. Name the first one SendTo, and the second Subject. Add an edit box to the form and name it MsgTxt.  Add a command button to the form. Set its Caption property to Send, and then add the following code to its Click event procedure: With This.Parent.OLEMAPIMsg .MsgIndex=-1 .RecipDisplayName=ALLTRIM(This.Parent.SendTo.Value) .MsgSubject=This.Parent.Subject.Value .MsgNoteText=This.Parent.MsgTxt.Value .SessionID=This.parent.olemapisession.sessionid .Send Endwith </li>  In the form's Destroy event procedure, add this code: Thisform.OLEMAPISession.SignOff </li> Save and run the form. If the mail application is not already running, the sign-on dialog box will appear and prompt for a password.</li> Enter a valid e-mail address in the SendTo box. Enter text for the subject in the Subject box. Enter the actual message text in the MsgTxt box.</li> Click the Send button. The mail message will be delivered to the specified e-mail address.</li> Close the form.</li></ol>

Keywords: kbhowto kbinterop KB135755

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.