How to Send a Mail Message in FoxPro for Windows

Last reviewed: October 18, 1996
Article ID: Q106033
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b

SUMMARY

The FoxPro Extensions that come with the Workgroup Templates enable FoxPro developers to tap into the mail messaging API (MAPI) and the Microsoft Schedule+ API (SPLUS).

All the necessary files are located on the Workgroup Extensions disk that ships with FoxPro for Windows, Professional edition.

Below is an example of how to send a mail message in FoxPro for Windows.

MORE INFORMATION

The FoxPro Extensions come with FOXMAPI.FLL, MAPILIB.PRG, and MAPIERR.PRG. FOXMAPI.FLL is a DLL that is the interface between FoxPro and MAPI.DLL and SPLUS.DLL. MAPILIB.PRG is a file containing procedures that make calls to functions in FOXMAPI.FLL (instead of calling the functions in FOXMAPI.FLL directly, parameters can be passed to MAPILIB.PRG, which provides extra error checking). MAPIERR.PRG is called by MAPILIB.PRG if an error condition occurs while a procedure in MAPILIB.PRG is being executed.

For more information about the functions used in this example, examine MAPILIB.PRG to find the function that is called in MAPILIB.PRG and then see what function MAPILIB.PRG calls in FOXMAPI.FLL. The Help file located in C:\WGTPLATE\APPENDIX\FOXPRO\FOXMAPI.HLP explains what the functions in FOXMAPI.FLL do.

For the following example to work, you must have FOXMAPI.FLL, MAPILIB.PRG, and MAPIERR.PRG. MAPILIB.PRG and MAPIERR.PRG should be in the same directory as the program below.

The following program sends a mail message to the e-mail name stored in m.toname; the subject line is stored in m.subject, and the text of the message is stored in m.notetext.

   ** START OF PROGRAM
   SET LIBRARY TO
   *:          Calls: MAPILIB()          (function in MAPILIB.PRG)
   *:               : MPLOGOFF()         (function in FOXMAPI.FLL)
   *:
   *:           Uses: MAPIMESG.DBF

   ** SET THE LIBRARY TO FOXMAPI.FLL
   SET LIBRARY TO C:\wgtplate\appendix\foxpro\foxmapi.fll

   ** MAPILIB.PRG and MAPIERR.PRG must be in the same directory
   ** as this program for things to work properly.

   ** MAPILIB.PRG calls FOXMAPI.FLL
   ** Log on to mail
   msession=MAPILIB('LOGON')

   ** Get Info To Send
   ** m.toname- The e-mail name of the person the message is addressed
   ** to.
   ** m.subject- The subject line of the e-mail message.
   ** m.notetext- The text of the e-mail message.
   m.tonames="johndoe"
   m.subject="MAIL TEST-A SAMPLE SUBJECT LINE"
   m.notetext="THIS IS A TEST OF SENDING MAIL WITH FOXPRO."

   ** create mapiRecip cursor
   ** resolve name
   =MAPILIB('resolve',msession,m.tonames)

   ** send message
   =MAPILIB('newcursor','mapiFile')
   =MAPILIB('newcursor','mapiMesg')


   INSERT INTO mapimesg VALUES(0,m.subject,m.notetext,'IPM.',;
      MAPILIB('getdate'),'',0,RECCOUNT('mapiRecip'),0)

   retval=mapilib("sendmail",msession,"mapiMesg","mapiRecip",;
      "mapiFile",0)

   ** Log off and cleanup
   ** Logging off by directly calling the mplogoff function in
   ** FOXMAPI.FLL
   =mplogoff(msession,0,0,0)

   CLEAR ALL
   CLOSE ALL
   RELEASE ALL
   SET LIBRARY TO
   ** END OF PROGRAM


Additional reference words: FoxWin 2.50 2.50a 2.50b email application
programming interface
KBCategory: kbinterop kbprg kbcode
KBSubcategory: FxtoolLck


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: October 18, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.