How To Send Mail Using MPSendMail() of FOXMAPI.FLL

Last reviewed: February 20, 1998
Article ID: Q152279
3.00 3.00b WINDOWS kbinterop kbhowto

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b
  • Microsoft FoxPro for Windows, versions 2.6, 2.6a

SUMMARY

Foxmapi.fll is a DLL interface to Mapi.dll and Splus.dll. This article describes how to use the MPSendMail function in FOXMAPI.

Information on obtaining the FOXMAPI files for your version of FoxPro is as follows:

  • FoxPro for Windows version 2.6x: Foxmapi.fll is provided with the separate product, Workgroup Extensions for FoxPro.
  • Visual FoxPro for Windows, version 3.0: For more information about obtaining FOXMAPI files, please see the following article in the Microsoft Knowledge Base:

    ARTICLE-ID: Q138255

       TITLE     : PATCH: Vfpmapi.exe Updated VFP for Windows FOXMAPI Files
    
    
  • Visual FoxPro for Windows, version 3.0b: Foxmapi.fll is located in the TOOLS\MAPI directory of the Visual FoxPro installation.

MORE INFORMATION

The following program will create and send a simple mail message. See the FOXMAPI.HLP file, provided with FOXMAPI.FLL, for explanations of error codes that may be returned by each function:

   #DEFINE success_success            0
   #DEFINE mp_e_type_not_supported   20

   ** Load FOXMAPI Library
   cLib = ""
   IF ! ("FOXMAPI" $ UPPER(SET("LIBRARY")))
      IF FILE("FOXMAPI.FLL")
         cLib = FULLPATH("FOXMAPI.FLL")
      ELSE
         cLib = LOCFILE("FOXMAPI.FLL","FLL","Where is FoxMAPI?")
         IF EMPTY(cLib)
            WAIT WINDOW "FOXMAPI Not Found ... press any key to exit"
            RETURN
         ENDIF
      ENDIF
      SET LIBRARY TO &cLib ADDITIVE
   ENDIF

   * Logon to Mail
   nSession = 0     && Variable to Receive MAPI session
   nSuccess = MPLogon(0,"","",1,0,@nSession)
   IF nSuccess # success_success
      DO errhand WITH nSuccess, "Login"
      RETURN
   ENDIF

   * Create FoxPro cursors for Message, Recipients,
   * and File Attachments
   lSuccess = MPCursor("MapiMesg")
   IF ! lSuccess
      WAIT WINDOW "Could not create Message Cursor ... " + ;
         " press any key to exit"
      RETURN
   ENDIF
   lSuccess = MPCursor("MapiRecip")
   IF ! lSuccess
      WAIT WINDOW "Could not create Recipients Cursor ... " + ;
         " press any key to exit"
      RETURN
   ENDIF
   lSuccess = MPCursor("MapiFile")
   IF ! lSuccess
      WAIT WINDOW "Could not create File Attachments Cursor " + ;
         " ... press any key to exit"
      RETURN
   ENDIF

   * Load the Message cursor
   SELECT MapiMesg
   APPEND BLANK
   * The reserved field must be 0 (zero)
   REPLACE reserved WITH 0
   * Change the text to your subject
   REPLACE subject WITH "My Subject"
   * Change the text to text of your message
   REPLACE notetext WITH "This is the text of my message"
   * RecipCount indicates the number of recipients. This should correspond
   * to the number of records in the MapiRecip cursor. For a simple
   * example, we will only use one (1).
   REPLACE recipcount WITH 1
   * FileCount indicates the number of file attachments. This should
   * correspond to the number of records in the MapiFile cursor. For a
   * simple example, we will not have any file attachments.
   REPLACE filecount WITH 0
   * Messagtype, if left blank, defaults to "IPM". If you receive
   * Unsupported Type on the MPSendMail function, you will need
   * to determine what type of message is required by your mail
   * system (you can do this by checking the Messagtype field after
   * using the MPReadMail function). The two remarked lines below
   * are examples that worked on two different systems.
   * REPLACE messagtype WITH "IPM.Microsoft Mail.Note"
   * REPLACE messagtype WITH "IPM.Note"

   * Load the Recipients cursor
   SELECT MapiRecip
   * The lines below would need to be repeated for each
   * recipient of your message.
   ****************
   APPEND BLANK
   * The reserved field must be zero (0)
   REPLACE reserved WITH 0
   * Change the text below to the name (email or friendly)
   * of the Recipient
   REPLACE name WITH "My Name"
   * Let Mail fill in the rest by resolving the name
   nSuccess = MPResolve(nSession, 0, mapirecip.name, ;
      0, 0, "MapiRecip")
   IF nSuccess # success_success
      DO errhand WITH nSuccess, "MPResolve"
      RETURN
   ENDIF
   ***************

   * Send the Message
   nSuccess = MPSendMail(nSession, 0, ;
      "MapiMesg", "MapiRecip", "MapiFile", 0, 0)
   DO CASE
      CASE nSuccess = mp_e_type_not_supported
         DO errhand WITH nSuccess, "MPSendMail", ;
            "Message Type Not Supported"
         RETURN
      CASE nSuccess # success_success
         DO errhand WITH nSuccess, "MPSendMail"
         RETURN
   ENDCASE

   * Logoff of Mail
   nSuccess = MPLogOff(nSession, 0, 0, 0)

   PROCEDURE errhand
      PARAMETER nErrnum, cLocation, cMessage
      message = "Error on " + cLocation + ": "
      IF EMPTY(cMessage)
         message = message + ALLTRIM(STR(nErrnum))
      ELSE
         message = message + cMessage
      ENDIF
      message = message + " ... press any key to exit"
      WAIT WINDOW message
      RELEASE LIBRARY FOXMAPI
      RETURN

NOTE: Under Microsoft FoxPro for Windows, version 2.x, Foxmapi.fll is designed to interface with Microsoft Mail. It may not work with Microsoft Exchange. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional reference words: 3.00 3.00b VFoxWin
KBCategory: kbinterop kbhowto
KBSubcategory: FxinteropGeneral
Keywords : FxinteropGeneral kbhowto kbinterop
Version : 3.00 3.00b
Platform : WINDOWS


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.

Last reviewed: February 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.